Not sure why [continue] is not working

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 12
Reputation: dabu is an unknown quantity at this point 
Solved Threads: 0
dabu dabu is offline Offline
Newbie Poster

Re: Not sure why [continue] is not working

 
0
  #11
Oct 28th, 2007
I tried getting rid of a loop and did this:

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double withdraw, deposit, balance, newBalance, amount;
  8. char ans;
  9. string choice;
  10.  
  11. balance = 1000;
  12.  
  13. cout << "Welcome to Whatever ATM!" << endl;
  14.  
  15. do
  16. {
  17. cout << "\nWhat would you like to do from the following?\n"
  18. << "\nWithdraw from account\n"
  19. << "Deposit money into account\n"
  20. << "Balance inquiry\n"
  21. << "Quit\n"
  22. << "\nPlease select now" << endl;
  23.  
  24. cin >> choice;
  25. ans = choice[0];
  26. newBalance = balance;
  27.  
  28. if ((ans == 'w') || (ans == 'W'))
  29. {
  30. cout << "\nWhat amount would you like to withdraw?" << endl;
  31. cin >> amount;
  32.  
  33. while (amount > balance)
  34. {
  35. cout << "Sorry, you have insufficient funds.\n"
  36. << "Please try again: ";
  37. cin >> amount;
  38. }
  39. if (amount <= balance)
  40. {
  41. balance = balance - amount;
  42. newBalance = balance;
  43. cout << "Thank you, your new balance is: " << newBalance << endl;
  44. cout << "Would you like to make another transaction? (Y/N)" << endl;
  45. cin >> ans;
  46. if ((ans == 'y') || (ans == 'Y'))
  47. continue;
  48. else
  49. break;
  50. }
  51. }
  52. else if ((ans == 'd') || (ans == 'D'))
  53. {
  54. cout << "\nWhat amount would you like to deposit?" << endl;
  55. cin >> amount;
  56. balance = balance + amount;
  57. newBalance = balance;
  58. cout << "Thank you, your new balance is: " << newBalance <<endl;
  59. cout << "Would you like to make another transaction? (Y/N)" << endl;
  60. cin >> ans;
  61. if ((ans == 'y') || (ans == 'Y'))
  62. continue;
  63. else
  64. break;
  65. }
  66. else if ((ans == 'b') || (ans == 'B'))
  67. {
  68. cout << "Your balance is: " << balance <<endl;
  69. cout << "Would you like to make another transaction? (Y/N)" << endl;
  70. cin >> ans;
  71. if ((ans == 'y') || (ans == 'Y'))
  72. continue;
  73. else
  74. break;
  75. }
  76. else if ((ans == 'q') || (ans =='q'))
  77. break;
  78. else
  79. continue;
  80. }
  81. while ((ans == 'w') || (ans == 'W') || (ans == 'd') || (ans == 'D')
  82. || (ans == 'b') || (ans == 'B') || (ans == 'q') || (ans == 'Q'));
  83.  
  84. cout << "\nThank you for banking with Whatever ATM!" << endl;
  85.  
  86. }

There is still something wrong and I cant figure it out. Could someone give me some insight?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,133
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Not sure why [continue] is not working

 
0
  #12
Oct 28th, 2007

So you didn't bother with my questions at all and just made a convoluted while statement? Then all you can say is "something is wrong -- go find it and tell me what to do"?

I don't think so...

I realize you're probably frustrated (so am I), but if you had followed my posts you might have learned something about how to debug your code.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: dabu is an unknown quantity at this point 
Solved Threads: 0
dabu dabu is offline Offline
Newbie Poster

Re: Not sure why [continue] is not working

 
0
  #13
Oct 28th, 2007
Originally Posted by WaltP View Post
First figure out why the loop exits. Then before the continue, defeat the exit condition.

Sorry Walt, I should have said that this statement was not clear to me before, but after re-reading it I understand and now my program works the way I want.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum


Views: 1193 | Replies: 12
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC