How to use switch to compare percentages.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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..

3rd Nov 2016, 4:23 PM
Ryn
Ryn - avatar
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; }
16th Nov 2016, 8:18 PM
AlamSirji
AlamSirji - avatar
+ 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; }
4th Nov 2016, 10:39 AM
MisterSir
MisterSir - avatar
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.
3rd Nov 2016, 4:28 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
you are asking me?
4th Nov 2016, 10:50 AM
Aditya kumar pandey
Aditya kumar pandey - avatar