Question

In: Computer Science

C++ Using what you know about inputs and outputs, code a simple ATM interaction. Your ATM...

C++

Using what you know about inputs and outputs, code a simple ATM interaction. Your ATM will start with only $500 to give out, and YOUR balance will be 1000. The amounts the ATM can dispense are $40, $80, $200 and $400. After you've received your disbursement, the console will show the amount you have left in your account, as well as how much the ATM has to dispense (we live in a small, fictional town - no one will use this information for nefarious purposes).

You may choose to use characters to show the interface, or just list the options for the user at the console.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Choose One

| $40 |$80

| $200 |$400

EXIT

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Solutions

Expert Solution

Save the following code in file atm.cpp .compile and run it.

#include <iostream>
using namespace std;

int main(){
int choice = 0;
int balance = 1000;
int withdrawal = 0;
int max_withdraw = 500;
int step_withdraw = 0;
cout<<"\nInitial Balance = "<<balance;
while(balance > 0 && withdrawal <= max_withdraw) {
//The choice Menu to ATM user
cout<<"\n>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
cout<< "Choose One" << endl;
cout<<"1. $40 "<< endl;
cout<<"2. $80 "<< endl;
cout<<"3. $200 "<< endl;
cout<<"4. $400 "<< endl;
cout<<"5. EXIT "<< endl;
cout<<">>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
  
cout<<"\nEnter your choice( 1 - 5): ";
  
cin>>choice;
// Take action as per choice...
switch(choice){
    case 1:
        step_withdraw = 40;
        break;
    case 2:
        step_withdraw = 80;
        break;
    case 3:
        step_withdraw = 200;
        break;
    case 4:
        step_withdraw = 400;
        break;
    case 5: exit(0);
default: cout<<"\nInvalid choice";
break;
}
// Maintain ATM balance
if(withdrawal + step_withdraw > max_withdraw){
cout<<"\nYou can't withdraw more than " << max_withdraw << endl;
exit(0);
}else{
balance = balance - step_withdraw;
withdrawal = withdrawal + step_withdraw;
cout <<"\nYour Balance = " << balance;
cout <<"\nYour total withdrawal = " << withdrawal;
}
}
return 0;
}

Here is the program output:


Initial Balance = 1000
>>>>>>>>>>>>>>>>>>>>>>>>>
Choose One
1. $40
2. $80
3. $200
4. $400
5. EXIT
>>>>>>>>>>>>>>>>>>>>>>>>>

Enter your choice( 1 - 5): 4

Your Balance = 600
Your total withdrawal = 400
>>>>>>>>>>>>>>>>>>>>>>>>>
Choose One
1. $40
2. $80
3. $200
4. $400
5. EXIT
>>>>>>>>>>>>>>>>>>>>>>>>>

Enter your choice( 1 - 5): 2

Your Balance = 520
Your total withdrawal = 480
>>>>>>>>>>>>>>>>>>>>>>>>>
Choose One
1. $40
2. $80
3. $200
4. $400
5. EXIT
>>>>>>>>>>>>>>>>>>>>>>>>>

Enter your choice( 1 - 5): 1

You can't withdraw more than 500




Related Solutions

C++ Using what you know about how to take inputs and make outputs to the console,...
C++ Using what you know about how to take inputs and make outputs to the console, create a check printing application. Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Using what you know about how to take inputs and make outputs to the console, create...
Using what you know about how to take inputs and make outputs to the console, create a check printing application. Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Please only use technique from chapter 1 through 3 in C++ from control structure through object 9th edition
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
Explain the inputs (and outputs if you know them) of the following Excel functions: • Norm.S.Dist()....
Explain the inputs (and outputs if you know them) of the following Excel functions: • Norm.S.Dist(). • Norm.Inv(). • T.Dist().
What are the inputs and outputs for functional analysis and allocation? Explain how inputs are transformed...
What are the inputs and outputs for functional analysis and allocation? Explain how inputs are transformed to outputs. In what life cycle phase(s) is functional analysis and allocation performed?
This is a question on the inputs and outputs on Basic javascript application What is the...
This is a question on the inputs and outputs on Basic javascript application What is the displayed output of the application if the user inputs Are: 1    in the first box, 2 in the second box, 3 in the third box, and 4 in the fourth box Modify the HTML and javascript file in order to Creates an h1 and a span element ii)          Accesses all the html elements, then adds the four input values as strings and sends the...
Your task is to determine the WACC for a given firm using what you know about...
Your task is to determine the WACC for a given firm using what you know about WACC as well as data you can find through research. Your deliverable is a brief report in which you state your determination of WACC, describe and justify how you determined the number, and provide relevant information as to the sources of your data. Select a publicly traded company that has debt or bonds and common stock to calculate the current WACC. One good source...
Using python Create a function that inputs a list of numbers and outputs the median of...
Using python Create a function that inputs a list of numbers and outputs the median of the numbers. sort them and them show the output.
Decide what you must know about (a) your future customers, (b) your future competitors, and (c)...
Decide what you must know about (a) your future customers, (b) your future competitors, and (c) other critical forces in the task environment if you are to be successful.
What are the outputs of the "Define activity phase" and the inputs to the "Sequence activity...
What are the outputs of the "Define activity phase" and the inputs to the "Sequence activity phase" in the project time management? Explain why the schedule produced by the Sequence activity phase cannot be used as a reference to manage the time of the project
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT