0

The following code works. However i want it so when the user reaches 500 dollars the last cout statement will run. But for some reason i can't get it to work properly. It skips the last cout statment and enters -numbers.

#include <iostream>
using namespace std;


int main ()
{

	int money = 500;
	int moneyspent;
	
	do
	{
	
	cout<<"Please enter how much money you would like to spend"<<endl;
	cin >> moneyspent;

	if(moneyspent < 500)
		
		money = money - moneyspent;
		
	cout<<"You have "<<money<<" dollars left to spend"<<endl;
	
	}
	while(moneyspent != 500);

	cout <<"You are out of cash jarboni"<<endl;

	return 0;

}
3
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by vegaseat
0

Pretend you're the computer, and keep track of the values of money and moneyspent given some arbitrary input values to the program. You'll see your problem.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.