0
How to use switch to compare percentages..
the program is like this: user need to input his percentage . the program should be like thi case 1 >=80 //formula used cout<<D case 2 >=60&&<80 // formula used cout<<FD etc... is it possible to use switch statement.?.I need to use switch not if else..
4 Answers
+ 5
@xxxfacepunchxxx
#include <iostream>
using namespace std;
int main() {
cout << "Are your older 18? Y / N" << endl;
char var;
cin >> var;
switch(var){
case 'y':
case 'Y':
cout << "come in!";
break;
case 'n':
case 'N':
cout << "too young!";
break;
default:
cout << "your answer isnt clear!";
break;
}
return 0;
}
+ 1
Hi everyone!
i have the same problem:
how to realise case 'y'||'Y' ?
#include <iostream>
using namespace std;
int main() {
cout << "Are your older 18? Y / N" << endl;
char var;
cin >> var;
switch(var){
case 'y'||'Y':
cout << "come in!";
break;
case 'n'||'N':
cout << "too young!";
break;
default:
cout << "your answer isnt clear!";
break;
}
return 0;
}
0
int x=80;
switch(x)
{
case 80 ... 90: cout << "wgfhh";
break;
case 10 ... 20: cout << "hjgfy";
break;
}
you can use range or value not >= like conditions, what you are asking is not standard GCC complier work.
0
you are asking me?