fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int prompt = NULL;
  6. cout << "1. Cube" << endl;
  7. cout << "2. Sphere" << endl;
  8. cout << "3. Prism" << endl;
  9. cout << "4. Cylinder" << endl;
  10. cout << "5. Cone" << endl;
  11. cout << "6. Quit" << endl;
  12. cout << "Choose an option by typing in the corresponding number: ";
  13.  
  14. while(!(cin >> prompt) || prompt < 0 || prompt > 6) cout << "Cannot read input.\nChoose an option between 1 and 6: ";
  15.  
  16. cout << "This worked: " << prompt << endl;
  17. }
Success #stdin #stdout 0s 4528KB
stdin
-13
42
6
stdout
1. Cube
2. Sphere
3. Prism
4. Cylinder
5. Cone
6. Quit
Choose an option by typing in the corresponding number: Cannot read input.
Choose an option between 1 and 6: Cannot read input.
Choose an option between 1 and 6: This worked: 6