+ 1

why won't this run?

#include <iostream> using namespace std; int main() { cout << "11+11="; int test; cin>>test; int Q2; switch(test){ case 23: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 21: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 20: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 19: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 18: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 17: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 16: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 15: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 24: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 25: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 26: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 27: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 28: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 29: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 30: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 31: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 32: cout <<"wrong\n 11+11=";cin >>test; cout <<"answer is 22\n 12+12=";cin<<Q2; break; case 22: cout <<"right\n 12+12="; cin>>Q2;} return 0; }

3rd Sep 2018, 11:28 PM
Benjamin Burks
Benjamin Burks - avatar
2 Respostas
+ 4
Insertion operator << for std::cout. Extraction operator >> for std::cin. You used both << and >> for cin. Just write 2 cases: 22 and default, if all the others are the same. Don't list 'em all out. Don't repeat code.
3rd Sep 2018, 11:48 PM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
0
thank you for your response, i will try that.
11th Sep 2018, 1:13 AM
Benjamin Burks
Benjamin Burks - avatar