Hi everyone,
I am in the process of learning C++ and having some difficulties and need some help figuring out the problem.
The program is to balance the account by reading an initial value, the deposits and withdraws and then print them out. The problem I have is that the loop will print an extra line when it is suppose to have been terminated.
I am using MS Visual C++...
Here is the code.
#include <iostream.h>
int main()
{
double new_balance = 0;
double initial_balance = 0;
double deposit = 0;
double withdraw = 0;
int index = 0;
cout <<"Please enter your account balance now: " << endl; // The initial amount
cin >> initial_balance;
new_balance = initial_balance;
do
{
cout << "Please enter a transaction to balance: " << endl;
cin >> index;
if(index>0) deposit += index; //total of deposits
else withdraw += index; //total of withdraws
new_balance += index;
cout << "Your new balance is: " << new_balance << "." << endl;
}
while (index != 0);
cout << "The total deposit for this session is: " << deposit << "." << endl;
cout << "The total debit for this session is: " << withdraw << "." << endl;
cout << "Your new balance as of today is: " << new_balance << "." << endl << endl;
return 0;
}
And here is what i got when I ran it..
Please enter your account balance now:
5000
Please enter a transaction to balance:
100
Your new balance is: 5100.
Please enter a transaction to balance:
150
Your new balance is: 5250.
Please enter a transaction to balance:
-130
Your new balance is: 5120.
Please enter a transaction to balance:
-10
Your new balance is: 5110.
Please enter a transaction to balance:
0
Your new balance is: 5110. Should it print this line out?...
The total deposit for this session is: 250.
The total debit for this session is: -140.
Your new balance as of today is: 5110.
Press any key to continue
Thanks for any help..