| | |
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:
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 |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






