0

What mistake i am doing in this code.

#include <iostream> using namespace std; int main() { int mark = 90; if (mark < 50) { cout << "You failed." << endl; } else { cout << "You passed." << endl; } if(mark=100){ cout <<"you are perfect"; } return 0; }

18th May 2019, 12:28 PM
Ravi Henry
Ravi Henry - avatar
7 Respuestas
+ 4
if(mark == 100) mark = 100 --> mark gets the value 100 mark == 100 --> using boolean operator to compare 100 with the value of mark. Is equal return true else return false
18th May 2019, 12:46 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
The sequence is If (){ } else if(){ } else if(){ } else if(){ } else if(){ } . . . . else{ }
18th May 2019, 3:13 PM
Bug Slayer
+ 2
Please look at the code. Hope it helps you. https://code.sololearn.com/cY71GtJLlKKk/?ref=app
18th May 2019, 12:39 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
There's a mistake on your last if statement. You wrote "if (mark=100)". The problem is that you're not doing a comparison. To compare two values, you need to use "==" Here, you're setting mark's value to 100 and evaluating it as a Boolean (condition) By convention, any numeric value that is not zero will return true when evaluated as a condition
18th May 2019, 12:45 PM
ThewyShift
ThewyShift - avatar
+ 1
Okey
18th May 2019, 12:46 PM
Ravi Henry
Ravi Henry - avatar
+ 1
Thx
18th May 2019, 3:20 PM
Ravi Henry
Ravi Henry - avatar
+ 1
Now I have got
18th May 2019, 3:20 PM
Ravi Henry
Ravi Henry - avatar