trying to make a "Do While" loop; loop

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 6
Reputation: alejo is an unknown quantity at this point 
Solved Threads: 0
alejo alejo is offline Offline
Newbie Poster

trying to make a "Do While" loop; loop

 
0
  #1
Mar 2nd, 2007
  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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

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

 
0
  #2
Mar 2nd, 2007
put the do in before this line:

cout << " Please enter two numbers: ";

and the while after the closing brace of the switch statement.
  1. } //end of switch statement
  2. cout << "\n Would you like to perform another calculation? " << endl;
  3. cin >> option;
  4. }while ( option == 'y' );
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 6
Reputation: alejo is an unknown quantity at this point 
Solved Threads: 0
alejo alejo is offline Offline
Newbie Poster

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

 
0
  #3
Mar 2nd, 2007
hahahahaha, i knew it was something silly, thank you very much...this was killing me. thank you!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC