| programmerrz (3) | |
|
i cant figure out how to exit the function when i input "no". any solutions? heres the function. #include <iostream> using namespace std; int yes=1; int no=2; void exit() { cin >> no >> endl; return; } int main() { cout << "Enter a number: "; // ask user for a number int x; int y; cin >> x; // read number from console and store it in x cout << "You entered " << x << endl; cout << "Do you wish to know what " << x << " squared is equal to?" << endl; cout << "For yes, type: " << yes << " For no, type: " << 2 << endl; cin >> yes; exit(); y=x*x; cout << x << " squared is equal to " << y << endl; return 0; } | |
|
Last edited on
|
|
| nano511 (361) | |||
|
First, you should surround code in code tags( the <> button under Format: ). You are doing way to much for such a simple program. Heres some pseudocode for you to figure out how to translate it to real code.
The window will close immediately though, so i added a line to keep it open. | |||
|
|
|||
| programmerrz (3) | |
| how would you code "if (response ==yes/no)?" | |
|
|
|
| nano511 (361) | |
|
When you prompt say something like "Would you like to square the number? For Yes, enter 1. For No, enter 2. if( response == 1)//yes etc. Or you could do "Would you like...? Y/N" if( response == Y)//yes etc. | |
|
|
|
| programmerrz (3) | |
| ok | |
|
Last edited on
|
|