+ 1
c++
The If statement Admission to the pool is free for children under 7 years of age. The given program takes age as an input. Task Complete the code to output "free" if the child's age is less than 7. Sample Input 6 Sample Output free Don't print anything if the age is above or equal to 7. I tried this way only 2 cases were right: #include <iostream> using namespace std; int main() { int age; cin >> age; if (age<7); cout<<"free"; // your code goes here return 0;
4 Answers
+ 5
You need to remove the semicolon after the if condition.
if (age <7)
...
+ 5
Generally, semicolon is used to end a statement. If you put this after if statement, if and cout are separated as two statements.
So, you always get "free" as output since it doesn't depend on if statement.
+ 2
@Simba thanks dude it worked but I don't understand why remove semicolon the if statement supposed to end with semicolon isn't it?
0
@Simba I did exact but case 3 was wrong: When input 8 it still prints free and supposed to print nothing