Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create ten accounts in an array with id 0 , 1 , . . . , 9 , and initial balance

ID: 3846162 • Letter: C

Question

Create ten accounts in an array with id 0 , 1 , . . . , 9 , and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Include exception handling so that if the user enters an id greater than 9, the program handles the issue in an elegant way. Once an id is accepted, the main menu is displayed as shown in the sample run. Please enter a choice: 1 for viewing the current balance 2 for withdrawing money 3 for depositing money 4 for exiting the main menu Once you choose (4) exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. If you would like to add another loop that allows the program to quit, that would be fine, but is not required.

Explanation / Answer

using System.IO;
using System;

class Program
{
static void Main()
{
int[] arr = {100,100,100,100,100,100,100,100,100,100};
int id, choice, amt, flag=1;
while(true)
{
Console.Write("Enter an id : ");
id = Convert.ToInt32(Console.ReadLine());
if(id >= 0 && id <= 9)
break;
Console.WriteLine("You gave invalid input, input range is 0-9.. Try again!!");
}
do
{
Console.WriteLine("1. View Current Balance");
Console.WriteLine("2. Withdraw Money");
Console.WriteLine("3. Deposit Money");
Console.WriteLine("4. Exit");
Console.Write("Enter your choice : ");
choice = Convert.ToInt32(Console.ReadLine());
switch(choice)
{
case 1:
Console.WriteLine("Total amount in the Balance is " + arr[id]);
break;
case 2:
Console.Write("Enter the money to withdraw : ");
amt = Convert.ToInt32(Console.ReadLine());
arr[id] = arr[id] - amt;
if(arr[id] <= 0)
arr[id] = 0;
break;
case 3:
Console.Write("Enter the money to deposit : ");
amt = Convert.ToInt32(Console.ReadLine());
arr[id] = arr[id] + amt;
break;
case 4:
while(true)
{
Console.Write("Enter an id : ");
id = Convert.ToInt32(Console.ReadLine());
if(id >= 0 && id <= 9)
break;
Console.WriteLine("You gave invalid input, input range is 0-9.. Try again!!");
}
break;
}
}while(flag==1);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote