944,155 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 5743
  • C++ RSS
Mar 2nd, 2007
0

trying to make a "Do While" loop; loop

Expand Post »
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4.  
  5. {
  6. char function;
  7. double num1, num2;
  8. char option;
  9. option = 'y';
  10.  
  11. cout << " Please enter two numbers: ";
  12. cin >> num1 >> num2;
  13. cout << "\n + for addition ";
  14. cout << "\n - for subtraction ";
  15. cout << "\n * for multiplication ";
  16. cout << "\n / for division " << endl;
  17. cout << "\n Select an operation to perform from the list above: ";
  18. cin >> function;
  19.  
  20. switch ( function )
  21. do
  22. {
  23. {
  24. case '+':
  25. cout << "\n " << num1 << " + " << num2 << " is your equation " << endl;
  26. cout << "\n The sum of your numbers is " << num1 + num2 << endl;
  27. break;
  28. case '-':
  29. cout << "\n " << num1 << " - " << num2 << " is your equation " << endl;
  30. cout << "\n The difference of your numbers is " << num1 - num2 << endl;
  31. break;
  32. case '*':
  33. cout << "\n " << num1 << " * " << num2 << " is your equation " << endl;
  34. cout << "\n The product of your numbers is " << num1 * num2 << endl;
  35. break;
  36. case '/':
  37. cout << "\n " << num1 << " / " << num2 << " is your equation " << endl;
  38. cout << "\n The dividend of your numbers is " << num1 / num2 << endl;
  39. break;
  40. default:
  41. cout << "\n You failed to select from the table provided " << endl;
  42. }
  43. while ( option == 'y' )
  44. cout << "\n Would you like to perform another calculation? " << endl;
  45. cin >> option;
  46. break;
  47. }
  48. cout << "\n I hope this helped ";
  49. return 0;
  50. }

this is not home work directly i am trying to add a loop to the already existing HW which is math function aspect. i cant seem to figure out how to just make a simple Yes or No loop. i have no problem making the loop if it needs to count... any way any one have any suggestions on how to help a newbie?

thanks in advance!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alejo is offline Offline
6 posts
since Mar 2007
Mar 2nd, 2007
0

Re: trying to make a "Do While" loop; loop

put the do in before this line:

cout << " Please enter two numbers: ";

and the while after the closing brace of the switch statement.
C++ Syntax (Toggle Plain Text)
  1. } //end of switch statement
  2. cout << "\n Would you like to perform another calculation? " << endl;
  3. cin >> option;
  4. }while ( option == 'y' );
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Mar 2nd, 2007
0

Re: trying to make a "Do While" loop; loop

hahahahaha, i knew it was something silly, thank you very much...this was killing me. thank you!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alejo is offline Offline
6 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Class Errors
Next Thread in C++ Forum Timeline: Vector of vectors & magic square issues





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC