ATM?

I'm trying to help a friend out with a program he's working on, but we're getting weird errors-after typing "Return" it closes randomly instead of reiterating the loop.

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
#include <iostream>
#include <conio.h>

//Make a program that simulates an ATM that will continue until you run out of money.
//Make two variables, one for dollars and one for cents.
//Make three buyable items...
//You start with $10.00 plus a random number of dollars and cents
using namespace std;
float cash = 10.00;
//char atm[128];
string atm;
bool mainmenu = false;

int main (){
	
	cout.setf(ios::showpoint);
	cout.precision(4);
	cout << "Welcome to THE Cash Register.\nType Return at anytime to return to the main menu.\n\n";
	while(1){
		cout << "What would you like to do?\n\nView Balance\nWithdraw\nDeposit\nRob the ATM\n\n";
		getline(cin, atm);
		if(!strcmp(atm.c_str(),"Withdraw")){
			cout << "\nHow much would you like to withdraw?\nYou can only withdraw in $1.00 increments.\n\n";
			//Figure out how to define a wanted withdrawal amount/int(?) and make error message if>int cash.
			float withdrawamount;
			cin >> withdrawamount;
			if(withdrawamount>cash)
               cout << "Blaahh wrongg blahahahh\n\n";
            else{
                 cout.precision(3);
                 cash -= withdrawamount;
                 cout << "Withdrawal succeeded.\nCurrent Balance: " << cash << "\n\n";
            }
            getline(cin, atm);
			if(!strcmp(atm.c_str(),"Return"))
            {
				system("cls");
				continue;
            }
			
		}
		else if(!strcmp(atm.c_str(),"View Balance")){
			cout << "\nCurrent Balance: " << cash << "\n\n";
			
			getline(cin, atm);
			if(!strcmp(atm.c_str(),"Return")){
				system("cls");
				continue;
            }
		}
		getch();
		return 0;
	}
}

Does anyone know what we're doing wrong?
Don't use strcmp(). Just use ==. Using !strcmp() makes your code difficult to read and counter-intuitive.

cin >> withdrawamount; Will also cause you trouble because it's not removing the newline from the stream.
Have a read through http://www.cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.