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; }
7 odpowiedzi
+ 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";
}
...
+ 4
Run the program.
+ 4
That's what your cin is for...
your switch is written wrong, though.
+ 2
Ok thanks
+ 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;
}
+ 1
I can't run it without input