0

How to use if-then-else statement?

8th Mar 2022, 12:51 PM
Arunesh Kishore
13 Answers
+ 4
Yash Kishore the code you posted is in BASIC language, not C++.
8th Mar 2022, 5:09 PM
Brian
Brian - avatar
+ 3
We need to use `==` operator to compare two objects while `=` is used for assigning values.
8th Mar 2022, 3:12 PM
Simba
Simba - avatar
+ 2
In wich language are you programming?
8th Mar 2022, 12:52 PM
Sarah
Sarah - avatar
+ 2
Sorry, I have been afk for the last hour But have you tried this? I'm not a pro in C++ but on my Sololearn it works if I do it like this: if (a = 18) { //your code b } else { //your code c }
8th Mar 2022, 2:01 PM
Sarah
Sarah - avatar
+ 2
Ah sorry, of course you're right. Otherwise it won't return a boolean value of course
8th Mar 2022, 3:24 PM
Sarah
Sarah - avatar
+ 1
C++
8th Mar 2022, 12:55 PM
Arunesh Kishore
+ 1
okay. Do you have an example of code where it didn't work? Maybe we can find the mistake here
8th Mar 2022, 12:56 PM
Sarah
Sarah - avatar
+ 1
Input "your age";a If a = 18 then goto b else goto c
8th Mar 2022, 12:57 PM
Arunesh Kishore
+ 1
OK thanks
8th Mar 2022, 2:14 PM
Arunesh Kishore
+ 1
if (condition 1) { // code block 1 } else if (condition 2){ // code block 2 } else { // code block 3 } Here:- If condition1 evaluates to true, the code block 1 is executed. If condition1 evaluates to false, then condition2 is evaluated. If condition2 is true, the code block 2 is executed. If condition2 is false, the code block 3 is executed.
9th Mar 2022, 8:02 PM
Aman Kumar
Aman Kumar - avatar
+ 1
if(boolean statements) { body} else{ body}
10th Mar 2022, 9:23 AM
Abhishek Pandey
Abhishek Pandey - avatar
0
OK bro
9th Mar 2022, 8:03 AM
Arunesh Kishore
0
age = 18 if(age): print("You're 18") else: print("You're not 18")
10th Mar 2022, 4:09 AM
Pasot
Pasot - avatar