Oct 21, 2021 at 11:14pm UTC
This is my first year taking coding so I'm a bit confused cause I'm currently trying to work on this homework assignment that's a little late lol. I can make my code look and do this for my balance and counters, but I can't figure out how to for the accumulators if that makes sense? I would appreciate any help!
Balance $ 105.00
Number of checks 2
Number of deposits 2
Number of charges 2
Total checks $ 100.00
Total deposits $ 150.00
Total charges $ 45.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include <iomanip> // For sring output
#include <iostream>
using namespace std;
int main()
{
cout << fixed << setprecision(2);
//Declarations
int menuOptions = 0;
double balanceAmount = 0.0;
double check = 0.0;
double charge = 0.0;
double deposit = 0.0;
double total = 0.0;
double totalCheck = 0;
double totalCharge = 0.0;
double totalDeposit = 0.0;
int numberOfChecks = 0;
int numberOfCharges = 0;
int numberOfDeposits = 0;
//Inputs
cout << "What Is Your Balance? $" << endl;
cin >> balanceAmount;
do {
//To Clear Screen
system("cls" );
//For Switch
cout << "Enter Menu Options (1 For Check) (2 For Deposit) (3 For Charge) (4 To Exit) : " << endl;
cin >> menuOptions;
//Switch Statments/ If's
switch (menuOptions)
{
case 1:
cout << "How Much Is The Check? $" << endl;
cin >> check;
if (check <= balanceAmount)
{
balanceAmount = balanceAmount - check;
numberOfChecks = numberOfChecks + 1;
check = check - balanceAmount;
}
else
{
cout << "Non Sufficent Funds, You Will Recieve a $35 NSF Fee" << endl;
balanceAmount = balanceAmount - 35;
numberOfCharges = numberOfCharges + 1;
charge = (charge + 35) - balanceAmount;
cout << "$" << total;
cout << endl;
}
break ;
case 2:
cout << "Enter The Deposit Amount: $" << endl;
cin >> deposit;
balanceAmount = balanceAmount + deposit;
numberOfDeposits = numberOfDeposits + 1;
deposit += deposit + balanceAmount;
cout << "Your Balance After The Deposit Is" << endl;
cout << "$" << total;
cout << endl;
break ;
case 3:
cout << "What Is The Charge? $" << endl;
cin >> charge;
if (charge <= balanceAmount)
{
cout << "Your Total Will Now Be" << endl;
balanceAmount = balanceAmount - charge;
numberOfCharges = numberOfCharges + 1;
charge = charge + 35;
cout << "$" << total;
cout << endl;
}
else
{
cout << "Your Card Has Been Declined" << endl;
}
break ;
case 4:
system("cls" ); //CLEAR SCREEN
cout << " Thanks For Stoping By! " << endl; //IN MIDDLE OF WHILE LOOPS SO TOTAL GOES FIRST
cout << fixed << setprecision(2);
total = balanceAmount;
cout << " Total Amount $" << setw(8) << total << endl;
cout << " Number Of Checks" << setw(16) << numberOfChecks << endl;
cout << " Number Of Deposits" << setw(14) << numberOfDeposits << endl;
cout << " Number Of Charges" << setw(15) << numberOfCharges << endl;
cout << " Total Check Amount $" << setw(8) << check << endl;
cout << " Total Deposit Amount $" << setw(8) << deposit << endl;
cout << " Total Charge Amount $" << setw(8) << charge << endl;
while (menuOptions != 4);
break ;
default :
cout << "Invalid Option, Please Try Again" << endl;
}
}while (menuOptions != 4);
return 0;
}
Last edited on Oct 21, 2021 at 11:35pm UTC
Oct 22, 2021 at 1:49am UTC
sorry, what do you want it to do? Explain exactly what you want ... there are several things you can call an accumulator...
line 95 does nothing. case 4 says its 4, so you don't loop. if you did manage to loop, it would be infinite.
unimportant here but consider
x = x+3
is the same as
x+=3 ... same for all the arithmetic operators, -= *= etc exist.
also unimportant, but using int types for pennies is cleaner than doubles, which will have roundoff at some point.