Answer to Question #322904 in C++ for herry

Question #322904

Write a program that uses a structure to store the following data about a customer account:


· Name


· Address


· City


 · Telephone Number


 · Account Balance


With a function of withdrawMoney( float amountwithdraw) and depositMoney(float amountdeposit).



1
Expert's answer
2022-04-05T10:36:33-0400
#include <iostream>
using namespace std;


struct Customer
{
    char name[50];
    char address[50];
    char city[50];
    char telephoneNumber[50];
    float balance;
};


void accountInfo(Customer customer) 
{
    cout << "\nName: " << customer.name << "\n";
    cout << "\nAddress: " << customer.address << "\n";
    cout << "\nCity: " << customer.city << "\n";
    cout << "\nTelephone number: " << customer.telephoneNumber << "\n";
    cout << "\nBalance: " << customer.balance << "\n\n";
}


void withdrawMoney(float amountWithdraw, Customer customer)
{
    float newBalance;


    cout << "Choose amount to withdraw: ";
    cin >> amountWithdraw;


    newBalance = customer.balance - amountWithdraw;


    customer.balance = newBalance;
}


void depositMoney(float amountDeposit, Customer customer)
{
    float newBalance;
    
    cout << "Choose amount to withdraw: ";
    cin >> amountDeposit;


    newBalance = customer.balance + amountDeposit;


    customer.balance = newBalance;
}


int main()
{
    Customer john = { "John", "Street-no.1", "London", "11-1278-5531", 1500.45f};


    float _amountWithdraw = 0;
    float _amountDeposit = 0;
    int choice;


    do
    {
        cout << "1. Account information" << "\n";
        cout << "2. Withdraw money" << "\n";
        cout << "3. DepositMoney" << "\n";
        cout << "\nChoose the operation: ";
        cin >> choice;


        switch (choice)
        {
        case 1:
            accountInfo(john);
            break;


        case 2:
            withdrawMoney(_amountWithdraw, john);
            break;


        case 3:
            depositMoney(_amountDeposit, john);
            break;


        case 4:
            exit(EXIT_SUCCESS);


        default:
            cout << "\nIncorrect choice, please try again" << "\n";
        }


    } while (choice != 4);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS