hi guys,
new to programming and i am a week behind our tutorials. i need to get 3 other qus done for last week.
Basicall i have to assume the processing of an ATM, using switches. I have made the menu so far but am having trouble getting the input from the user.
I have to assume there is already a bank account and therefore must be a variable for the balance in the account.
With the switch statement the program must:
- output the balance on the screen
- let the user add (deposit) an amount to the existing balance
- let the user subtract (withdraw) an amount from the balance
I have made the menu and i have made a default so if anything else is entered the user will be informed of an error.I have also started putting together the forumla for calculating the balance if when a user inputs a deposit or withdrawl amount.
Everytime you choose an option from the menu i get the default??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
using namespace std;
int main()
{
int option, dep, balance, wth;
cout << "Please choose from the following: " << endl;
cout << "B - Show balance. D - Deposit. W - Withdrawal. " << endl;
cin >> option;
switch (option)
{
case 'B':
cout << "B. Show balance. ";
cout << "your balance is: $ " << balance;
break;
case 'D':
cout << "D. Deposit. ";
cin >> dep;
balance = balance + dep;
cout << "You have deposited: " << dep << " dollars";
break;
case 'W':
cout << "W. Withdrawal. ";
cin >> wth;
balance = balance - wth;
cout << "you have withdrawn: " << wth << " dollars";
break;
default:
cout << "invalid option." << endl;
}
system ("pause");
return 0;
}
|