Question

In: Computer Science

Part 3 Write a C++ program that prompts the user for an Account Number(a whole number)....

Part 3

Write a C++ program that prompts the user for an Account Number(a whole number). It will then prompt the user for the initial account balance (a double). The user will then enter either w, d, or z to indicate the desire to withdraw an amount from the bank, deposit an amount or end the transactions for that account((accept either uppercase or lowercase). You must use a nested if statements instead of a Switch construct.

Test Run:

Enter the account number: 1

Enter the initial balance: 5000

SAVINGS ACCOUNT TRANSACTION

(W)ithdrawal

(D)eposit

(Z) to end account transaction

Enter first letter of transaction type (W, D or Z): w

Amount: $1000

Balance for this account is now: $4000.00

SAVINGS ACCOUNT TRANSACTION

(W)ithdrawal

(D)eposit

(Z) to end account transaction

Enter first letter of transaction type (W, D or Z): d

Amount: $500

Balance for this account is now: $4500.00

SAVINGS ACCOUNT TRANSACTION

(W)ithdrawal

(D)eposit

(Z) to end account transaction

Enter first letter of transaction type (W, D or Z): z

No more changes.

Balance for this account is now: $4500.00

Press any key to continue . . .

Solutions

Expert Solution

Code

#include<iostream>
using namespace std;

int main()
{
    int an; //account number
    cout << "Enter the account number: ";
    cin>>an;
    double ib;
    double bal=0;
    cout<<"Enter the initial balance: ";
    cin>>ib;
    bal=bal+ib;
    double amount;
    char ch;
    while(1)
    {
        cout<<"SAVINGS ACCOUNT TRANSACTION";
        cout<<"\n(W)ithdrawal\n(D)eposit\n(Z) to end account transaction\nEnter first letter of transaction type (W, D or Z):";
        cin>>ch;
        if(ch=='z' || ch=='Z') //if z entered print messages and exit
        {
            cout<<"No more changes.\n";
            printf("Balance for this account is now: %.2f",bal);
            cout<<"\nPress any key to continue . . .";
            break;
        }
        cout<<"Amount: $";
        cin>>amount;
        if(ch=='w' || ch=='W')
        {
            if(amount<=bal)
            {
                bal=bal-amount;
            }
            else // low balance 
                cout<<"balance is less than withdrawal amount";
        }
        if(ch=='d' || ch=='D')
        {
            bal=bal+amount;
        }
        printf("Balance for this account is now: $%.2lf",bal);
        cout<<"\n";
    }
    return 0;
}

Terminal Work

.


Related Solutions

Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and a base in the range 2 <= base <= 16. Write a function multibaseOutput() that displays the number in the specified base. The program terminates when the user enters a number of 0 and a base 0. Run: Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 155 16     155 base 16 is 9B Enter...
C Program 1. Write a program that prompts the user to enter 3 integers between 1...
C Program 1. Write a program that prompts the user to enter 3 integers between 1 and 100 from the keyboard in function main and then calls a function to find the average of the three numbers. The function should return the average as a floating point number. Print the average from main.The function header line will look something like this:float average(int n1, int n2, int n3) STOP! Get this part working before going to part 2. 2. Create a...
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT