0% found this document useful (0 votes)
3 views2 pages

exercises C++

Uploaded by

dz32494
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

exercises C++

Uploaded by

dz32494
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;

int main() {
double balance = 0.0;
int choice;
double amount;

while (true) {
cout << "1. Check Balance" << endl;
cout << "2. Deposit Funds" << endl;
cout << "3. Withdraw Funds" << endl;
cout << "4. Exit" << endl;

cout << "Choose an option: ";


cin >> choice;

if (choice < 1 || choice > 4) {


cout << "Error" << endl;
}
else if (choice == 1) {
cout << "Balance: $" << balance << endl;
}
else if (choice == 2) {
cout << "Deposit amount: $";
cin >> amount;

while (amount <= 0) {


cout << "Error. Enter a positive number: $";
cin >> amount;
}

balance += amount;
cout << "Deposited: $" << amount << ". Balance: $" << balance << endl;
}
else if (choice == 3) {
if (balance <= 0) {
cout << "Error" << endl;
}
else {
cout << "Withdrawal amount: $";
cin >> amount;

if (amount <= 0 || amount > balance) {


cout << "Error" << endl;
}
else {
balance -= amount;
cout << "Withdrew: $" << amount << ". Balance: $" << balance <<
endl;
}
}
}
else if (choice == 4) {
cout << "Goodbye!" << endl;
break;
}
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy