I have a quick question with a code I am doing. I am enteringa deposit in an atm
ID: 3617662 • Letter: I
Question
I have a quick question with a code I am doing. I am enteringa deposit in an atm program and I have an option after the amountis entered to ask the user to enter a new transaction. Anyways what I am trying to do is get the function to accumulatethe money so it will return an error if the total deposits for theatm exceed 10000. Here is my code for the function. Ihave no problem sending the entire code but it is over 1000 linesso if any of you guys can take a look a this without the entirecode please let me knowvoid depositTest(double money)
{
double depositTotal = 0;
while (money <= 10000 && choice ==2)
{
depositTotal += money;
}
//if money is greater than 10000 ifstatement
if (money > 10000 && choice == 2)
{
//show an error message
cout << endl <<"This ATM has encountered the following error...";
cout << endl <<"This atm has reached the total amount of deposits it canhold.";
cout << endl <<"We apologize for this inconvenience.";
cout << endl;
//exit the program if theerror occurs
exit(0);
}
}
Explanation / Answer
Since it isn't the entire code, I don't know if there are moreproblems. Based off only what is here: 1) I see no choice variabledeclared. Either it's in your main() function andyou need to pass it by value/reference to yourdepositTest() function or you need to declare itlocally inside this function. 2) That first while loop is a big issue. Thevariable money is passed by value to thisfunction. If it happens to beRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.