What will be the input of this program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What will be the input of this program?

#include <iostream> using namespace std; int main() { int age; cin>>age; switch(age<20){ case 1: cout<<"you are 22 years old"; break; case 2: cout<<"you are 32 years old"; break; default: cout<<"no special cases"; } return 0; }

6th Nov 2023, 9:04 AM
Haram Abbas
Haram Abbas - avatar
6 Answers
+ 6
Haram Abbas , furst of all the code should be written well-formed, this will increase the readability. input requires an int value. a working switch case could be like: ... int main() { int age; cin>>age; switch(age){ case 22: cout<<"you are 22 years old"; break; case ... ... default: cout<<"no special cases"; } ...
6th Nov 2023, 12:03 PM
Lothar
Lothar - avatar
+ 4
Run the program.
6th Nov 2023, 10:23 AM
Lisa
Lisa - avatar
+ 4
That's what your cin is for... your switch is written wrong, though.
6th Nov 2023, 11:11 AM
Bob_Li
Bob_Li - avatar
+ 2
Ok thanks
6th Nov 2023, 12:05 PM
Haram Abbas
Haram Abbas - avatar
+ 2
it switch not if/else statement solution:- What will be the input of this program? #include <iostream> using namespace std; int main() { int age; cin>>age; switch(age){ case 22: cout<<"you are 22 years old"; break; case 32: cout<<"you are 32 years old"; break; default: cout<<"no special cases"; } return 0; }
7th Nov 2023, 11:54 AM
Alhaaz
Alhaaz - avatar
+ 1
I can't run it without input
6th Nov 2023, 10:51 AM
Haram Abbas
Haram Abbas - avatar