| | |
trying to make a "Do While" loop; loop
Thread Solved
![]() |
•
•
Join Date: Mar 2007
Posts: 6
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { char function; double num1, num2; char option; option = 'y'; cout << " Please enter two numbers: "; cin >> num1 >> num2; cout << "\n + for addition "; cout << "\n - for subtraction "; cout << "\n * for multiplication "; cout << "\n / for division " << endl; cout << "\n Select an operation to perform from the list above: "; cin >> function; switch ( function ) do { { case '+': cout << "\n " << num1 << " + " << num2 << " is your equation " << endl; cout << "\n The sum of your numbers is " << num1 + num2 << endl; break; case '-': cout << "\n " << num1 << " - " << num2 << " is your equation " << endl; cout << "\n The difference of your numbers is " << num1 - num2 << endl; break; case '*': cout << "\n " << num1 << " * " << num2 << " is your equation " << endl; cout << "\n The product of your numbers is " << num1 * num2 << endl; break; case '/': cout << "\n " << num1 << " / " << num2 << " is your equation " << endl; cout << "\n The dividend of your numbers is " << num1 / num2 << endl; break; default: cout << "\n You failed to select from the table provided " << endl; } while ( option == 'y' ) cout << "\n Would you like to perform another calculation? " << endl; cin >> option; break; } cout << "\n I hope this helped "; return 0; }
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!
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
put the do in before this line:
cout << " Please enter two numbers: ";
and the while after the closing brace of the switch statement.
cout << " Please enter two numbers: ";
and the while after the closing brace of the switch statement.
C++ Syntax (Toggle Plain Text)
} //end of switch statement cout << "\n Would you like to perform another calculation? " << endl; cin >> option; }while ( option == 'y' );
![]() |
Similar Threads
- awk "for loop" and variables (Shell Scripting)
- my #include <string> wont make "string" bold (C++)
- error mgs when trying to compute "for loop" (C++)
- problem creating a for loop for an array (C++)
- how to make maze game using "gotoxy" & getch? (C++)
- Help with iteration in 'while' loop (C++)
Other Threads in the C++ Forum
- Previous Thread: Class Errors
- Next Thread: Vector of vectors & magic square issues
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






