i need help with my code and i am so stuck and i don't where my errors, i seriously need help fixing it, it supposed to be a program that displays what your balance is,your deposits, and withdrawals. i am also supposed to include double getAmount(string msg) and double getAmount(string msg, double balance), but I can't see where to put it.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
usingnamespace std;
int input;
constint TOTAL_MONTHS = 3;
int main()
{
double getAmount;
double totalDeposit;
double totalWithdrawal;
double currentBalance;
double startingBalance;
double balance;
double withdrawal;
double deposit;
double totalBalance;
double finalBalance;
cout << "Enter your current Balance";
cin >> startingBalance;
cout << "Enter the amount you want to deposit.\n";
cin >> deposit;
for (input = 1; input <= TOTAL_MONTHS; input++)
{
while (deposit < 0)
{
cout << "Sorry, amount invalid, try again.\n" << endl;
cin >> deposit;
}
cout << "Please enter the current withdrawal for the month\n";
cin >> withdrawal;
while (withdrawal < 0 || withdrawal > startingBalance)
{
cout << "Sorry, amount invalid, your withdrawal can not be greater than your current balance.Please try again.\n";
cin >> withdrawal;
}
totalBalance = startingBalance - finalBalance;
startingBalance = totalBalance + deposit;
finalBalance = totalBalance - withdrawal;
}
cout << "Here is your starting balance at the beginning of the three-month period." << startingBalance
<< endl;
cout << "Here is your total deposit during the three month period" << deposit << endl;
cout << " Here is your total withdrawals" << withdrawal << endl;
cout << "And your final balance at the end of the three-month period" << totalBalance << endl;
system("pause");
return 0;
}
It appears you have an uncontrolled loop regarding withdrawals.
Any errors along these lines will show up by referring back to your pseudocode or other schematic plan for this project. Perhaps you'd like to show us that plan and we can go through it with you so you can make the changes to your code.
But you really need to describe the problem you are having because our mind-readers are away again today. :)
It appears that the loop going out of control is because you are not resetting the deposits and withdrawals to an acceptable value for the additional loops through the while structures. They are using values you have left from the previous month.
what I planned on doing with the program was for it to display my options correctly once without it skipping any lines a or repeating the option several times, seems I have messed up at either my my loop function or initializing my variables properly. Also for some reason, I don't why the program requires me to put in two deposits instead of one when it ask for "enter current deposit for the month"? When I made my loop the first time, it didn't react this way. I guess I may have switch some things from the loop.
If you look very carefully at the code extract I've posted above you will be able to extend it to withdrawals and complete the for loop. It is very nearly a cut and paste job to incorporate it with your code.
oh i even forgot, how can I add dollar values to my code? i really dont want to use cout, if there is a function that can apply to my entire code, but if not then how will i display it in cout.