How to make ~case age>20:statement~ can be activated | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make ~case age>20:statement~ can be activated

Here is the code http://www.sololearn.com/app/cplusplus/playground/cMVEOlcOVwle/

25th Jun 2016, 11:45 AM
JS of MC(not C++ || java)
JS of MC(not C++ || java) - avatar
7 Answers
0
Maybe I write wrong thing
25th Jun 2016, 12:42 PM
JS of MC(not C++ || java)
JS of MC(not C++ || java) - avatar
0
#include<iostream> using namespace std; int main(){ string age = "age \> 20";//outputs litteraly cout << age; } or replace by: int age = 21; cout << (age>20) << endl; and you'll get 1 which is same as a "true"...
25th Jun 2016, 12:48 PM
Nikola Dedović
0
int age; cin >> age; if(age>20){ cout<<"You aren't old..."<<endl; } you don't need return 0... compiler knows...
25th Jun 2016, 1:21 PM
Nikola Dedović
0
in your case of a switch statement, you just need to put age>20 in parentheses in order to work...
25th Jun 2016, 1:23 PM
Nikola Dedović
0
Thanks! return 0 is just come with program it's really annoying >:), anyway.sooo switch isnt suppose right?
25th Jun 2016, 1:24 PM
JS of MC(not C++ || java)
JS of MC(not C++ || java) - avatar
0
in switch, cases must be a constants, expressions with a fixed value... age>20 is not a constant...
25th Jun 2016, 1:31 PM
Nikola Dedović
0
Thx very much :)
26th Jun 2016, 7:59 AM
JS of MC(not C++ || java)
JS of MC(not C++ || java) - avatar