I can't compile because the compiler cant finde the stdafx.h
But also I noticed tha the beggining of the main() is its end also... You should use the entry bracket "{" instead of ";". If you want to declare
1 2 3 4 5
|
int balance;//indicates the balance
int withamount;//indicates the amount to withdrawl
int depamount;//indicates the amount to deposit
char again;
char which;
|
as global variables you should do it before the main.
Also you use variables n,d,b,w without initializing them.
If you want to check if the "which" char is one of those then you should use:
if(which=='d')
The '=' operator assign a value to a variable. The '==' check for equality. Also because it is a char you have to use single quotes ' ' and put in there your character.
Also you have:
balance - withamount;
which doesn't mean anything... If I understood well you need to assign to balance the current amount of balance minus the withamount. Such a syntax would be
balance = balance - withamount;
or
balance -= withamount;
Finally for the if statements
1 2 3
|
if ( which = w )
if ( which = d )
if ( which = b )
|
You probably want to do all the folowin actions so you have to use brackets "{}" or else it will only execute the one following command as the commands of the if statements.
Also the escape character to change line is \n and not /n...
So, if I undestood well your code you probaby ment to do something like:
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
|
#include <stdafx>
#include <iostream>
using namespace std;
int balance;//indicates the balance
int withamount;//indicates the amount to withdrawl
int depamount;//indicates the amount to deposit
char again;
char which;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Please enter your beginning balance: ";
cin >> balance;
while ( again != 'n' )
{
cout<< "\nWould you like to withdrawal, or deposit? (w for withdrawal, d for deposit)(or press b to check you blance if you wish): ";
cin >> which; // You forgot to w8 for an input...
if ( which == 'w' ){
cout << " Please state the amount you would like to withdrawal: ";
cin >> withamount;
balance -= withamount;
cout << " Your balance after the withdrawal of: " << withamount << "is: " << balance << '\n';
}
if ( which == 'd' ){
cout << "Please state the amount you would like to deposit: ";
cin >> depamount;
balance += depamount;
cout << "Your balance after the deposit of: " << depamount << " is: " << balance << '\n';
}
if ( which == 'b' )
cout << "Your current balance is: " << balance;//Now you only want to execute this command as part of the if
cout << "Would you like to make another transaction? (y for yes, n for no): ";
cin >> again;
system ("pause");
}
return 0;
}
|
One technique, that works for me, is to write your program in parts. What i mean is to make sure something works before going on. I do it even for the declaration of the main() so i can be sure that i don't have anything wrong because of mistype.
Hope that helps.
[edit] When you paste code it is better to use the # button and write your code between the code /code so it can be easier readable...