+ 2
Help with a c++ code
I made a code for naming the age: https://code.sololearn.com/cRjx536WluKW/?ref=app I made a mistake i guess, because it outputs "Adult" everytime nomatter what the input is. Could someone help me? Obviosly I don't see the mistake.
7 odpowiedzi
+ 9
// Here is a workable version.
#include <iostream>
using namespace std;
int main() {
//int x; unneccessary variable
int age = 0;
cin >> age;
//{
if (age >= 14) {
if(age >= 18) {
cout << "Adult";
}
else {
cout << "Teenager";
}
}
else {
if (age > 0) {
cout << "Child";
}
else {
cout << "Something's wrong";
}
}
//}
}
+ 9
That's right, you also should be careful about braces and nesting too many conditional statements. But, your code is well-written and quite readable, my friend.
+ 4
Remove int x and just cin to age.
int age;
cin >> age;
+ 3
Thanks😀
+ 2
Well that was fast and easy
thanks!
+ 2
So my mistake was that i added a var x that was not like my var age so that there was no input for var age i guess
+ 1
Well that was fast and easy
thanks!