New to C++ need some help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 23
Reputation: simon126 is an unknown quantity at this point 
Solved Threads: 0
simon126 simon126 is offline Offline
Newbie Poster

New to C++ need some help

 
0
  #1
Oct 29th, 2005
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.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main ()
  6. {
  7.  
  8. int money = 500;
  9. int moneyspent;
  10.  
  11. do
  12. {
  13.  
  14. cout<<"Please enter how much money you would like to spend"<<endl;
  15. cin >> moneyspent;
  16.  
  17. if(moneyspent < 500)
  18.  
  19. money = money - moneyspent;
  20.  
  21. cout<<"You have "<<money<<" dollars left to spend"<<endl;
  22.  
  23. }
  24. while(moneyspent != 500);
  25.  
  26. cout <<"You are out of cash jarboni"<<endl;
  27.  
  28. return 0;
  29.  
  30. }
Last edited by Dave Sinkula; Oct 29th, 2005 at 6:33 pm. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 23
Reputation: simon126 is an unknown quantity at this point 
Solved Threads: 0
simon126 simon126 is offline Offline
Newbie Poster

Re: New to C++ need some help

 
0
  #2
Oct 29th, 2005
please help
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: New to C++ need some help

 
0
  #3
Oct 29th, 2005
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.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,055
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 935
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: New to C++ need some help

 
0
  #4
Oct 29th, 2005
Hint: You loop while your money is above zero!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC