Hey guys bit of newbie with coding, only my second code ever. Having a bit of trouble getting my program to compile. Im sure they are easy fixes but im just not sure. ATM machine that utilizes a menu system.First gets users pin number. Then allows for withdrawals, deposits, of checking and savings accounts. Can check current balance also.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream> //input output stream
#include <cstdlib> //C standard library
#include <cmath> //for fmod function
using namespace std; //cin and cout
void main_menu();
int main () {
double check = 100, //starting checking balance
save = 100, //starting savings balance
withdraw, //withdrawal amount
deposit; //deposit amount
int option = 0, //menu selection
PIN = 0, //Input PIN number
selection = 0; //deposit or withdrawal selection
cout.setf (ios::fixed);
cout.setf (ios::showpoint);
cout.precision (2);
cout << "Enter PIN\n";
for(int i =0; (PIN != 4321); ++i){ //Allows 3 tries
if (i == 3){
cout << "3 Invalid Inputs, dont make me shred your card!\n";
return EXIT_SUCCESS;
}
cout << "Please Enter Your 4 Digit PIN\n> ";
cin >> PIN; //Gets PIN
}
main_menu(); //main menu system
while(option != 4){ //navigates through menu
cout << "> "; //4 exits program
cin >> option;
switch(option){
case 1:
cout << "Choose The Account You Wish To\n"
<< "Make A Withdrawal.\n"
<< "[1] Checking\n" //withdrawal menu
<< "[2] Savings\n"
<< "[3] Cancel\n> ";
cin >> selection; //gets menu selection
switch(selection){ //navigates through menu
case 1: //checking withdrawal
cout << "[[[WITHDRAW]]]\n"
<< "Must Be A Multiple Of $5.00\n>";
cin >> withdraw; //gets amount, checks for mult of 5
while(fmod(withdraw,5.00)!=0){
cout << "Not A Multiple Of $5.00. Try Again\n> ";
cin >> withdraw;
}
if(withdraw > check){ //overdraft protection
cout << "Insufficient Funds In Account To\n"
<< "Withdraw $" << withdraw << endl << endl;
}else{
check -= withdraw; //calculates new balance
}
break;
case 2: //savings withdrawal
cout << "[[[WITHDRAW]]]\n";
cout << "Must be a multiple Of $5.00\n> ";
cin >> withdraw; //gets amount, checks for mult of 5
while(fmod(withdraw,5.00)!=0){
cout << "Not A Multiple Of $5.00. Try Again\n> ";
cin >> withdraw;
}
if(withdraw > save){ //wont let you overdraw
cout << "Insufficient funds in the account\n"
<< "withdraw $" << withdraw << endl << endl;
}else{
save -= withdraw; //calclulates new balance
}
break;
case 3: //exits withdrawal menu
break;
default: //allows more than one attempt
cout << "Invalid option " << selection
<< " Try Again\n";
cout << "Choose The Account You Wish To\n"
<< "Make A Withdrawal\n"
<< "[1] Checking\n"
<< "[2] Savings\n"
<< "[3] Cancel\n> ";
cin >> selection;
break;
case 2:
cout << "Choose the account to\n"
<< "make a Deposit\n"
<< "[1] Checking\n" //deposit menu
<< "[2] Savings\n"
<< "[3] Cancel\n> ";
cin >> selection; //gets menu selection
switch(selection){ //navigates through menu
case 1: //checking deposit
cout << "[[[DEPOSIT]]]\n";
cin >> deposit;
check += deposit; //calculates new balance
break;
case 2: //savings deposit
cout << "[[[DEPOSIT]]]\n> ";
cin >> deposit;
save += deposit; //calculates new balance
break;
case 3: //exits menu
break;
default: //allows more than one attempt
cout << "Invalid option " << selection
<< " Try Again\n";
cout << "Choose The Account You Wish To\n"
<< "Make A Withdrawal\n"
<< "[1] Checking\n"
<< "[2] Savings\n"
<< "[3] Cancel\n> ";
cin >> selection;
break;
case 3:
cout << "Checking Balance: $" << check << endl;
cout << "Savings Balance: $" << save << endl << endl;
main_menu(); //let them make another choice
break;
case 4: //exits
break;
default: //allows retries
cout << option << " Is not a valid "
<< "choice, please try again\n";
}
}
return EXIT_SUCCESS;
}
//*****************************************************
void main_menu(){ //main menu
cout << "Please select a number\n"
<< "for your desired action\n"
<< "[1] Withdrawal\n"
<< "[2] Deposit\n"
<< "[3] Check Balances\n"
<< "[4] Quit\n";
}
//**************************************************
|
Errors:
prog2.cc: In function 'int main()':
prog2.cc:125:1: error: duplicate case value
case 2:
^
prog2.cc:97:7: error: previously used here
case 2: //savings withdrawal
^
prog2.cc:156:1: error: duplicate case value
case 3:
^
prog2.cc:144:7: error: previously used here
case 3: //exits menu
^
prog2.cc:164:7: error: multiple default labels in one switch
default: //allows retries
^
prog2.cc:146:7: error: this is the first default label
default: //allows more than one attempt
^
prog2.cc:174:17: error: a function-definition is not allowed here before '{' token
void main_menu(){ //main menu
^
prog2.cc:181:1: error: expected '}' at end of input
}
^
prog2.cc:181:1: error: expected '}' at end of input
line numbers will be off, didn't include my header.
The bottom error has something to do with my function, but im not seeing whats wrong with it, and im not sure of you can switch within a switch so that could be causing the other problems. Other than that i feel like it should be working. Any help would be awesome.