Home > Back-end >  Can you help me check my this the if - else - if?
Can you help me check my this the if - else - if?

Time:09-22

Int main ()
{
Int hight.
Scanf_s (" % d ", & amp; Hight);
If (hight & gt;
=180){
Printf (" xiaoming can enter the basketball team ");
}
Else if (175 & lt;=hight & lt; 180)
{
Printf (" xiaoming can enter the basketball reserve ");
}
The else (hight & lt; 175);
{
Printf (" xiao Ming can't enter the basketball team ");
}
return 0;
}
Then debug result:
160
Xiao Ming can enter the substitute xiao Ming can't enter the basketball team basketball team
E: \ ConsoleApplication12 \ Debug \ ConsoleApplication12 exe process (11664) have withdrawn, the code is 0,
To debug stops automatically shut down the console, please enable "tool" - & gt;" Options - & gt; "" Debugging - & gt; "" Debugging stops automatically shut down the console, "
Press any key to close this window...
I just learn C, I am using Visual Studio, the programming software problem?

CodePudding user response:

Not have this kind of writing (175 & lt;=hight & lt; 180).

CodePudding user response:

Don't doubt the software problem, first thought is their own problems, to find their own problems easier than looking for a software problem, can change to this
If (hight & gt;
=180)14
{
15
Printf (" xiaoming can enter the basketball team ");
16
}
17
Else if (175 & lt;=hight & amp; & Hight & lt; 180)
18
{
19
Printf (" xiaoming can enter the basketball reserve ");
20
}
21
The else (hight & lt; 175);
22
{
23
Printf (" xiao Ming can't enter the basketball team ");
24
}

CodePudding user response:

Ok, don't understand asked,
Int main ()
{
Int hight.
Scanf_s (" % d ", & amp; Hight);
If (hight & gt;
=180){
Printf (" xiaoming can enter the basketball team ");
}
Else if (175 & lt;=hight & amp; & Hight & lt; 180)
{
Printf (" xiaoming can enter the basketball reserve ");
}
The else (hight & lt; 175);
{
Printf (" xiao Ming can't into the basketball team ");
}
return 0;
}
Results: 176
Xiao Ming can enter the basketball team can't substitute Ming into the basketball team
Changed:
Int main ()
{
Int hight.
Scanf_s (" % d ", & amp; Hight);
If (hight & gt;
=180){
Printf (" xiaoming can enter the basketball team ");
}
Else if (175 & lt;=hight & amp; & Hight & lt; 180)
{
Printf (" xiaoming can enter the basketball reserve ");
}
Else if (hight & lt; 175)
{
Printf (" xiao Ming can't into the basketball team ");
}
return 0;
}
Results: 176
Xiao Ming can enter the basketball reserve
I was in the third else + the if, how two results before and after different?

CodePudding user response:

The first to the last else behind a semicolon

CodePudding user response:

CodePudding user response:

refer to fifth floor See - Victory reply:

The last else didn't bring the if, or don't

CodePudding user response:

 int main () 
{
Int hight.
Scanf_s (" % d ", & amp; Hight);
If (hight & gt;
=180){
Printf (" xiaoming can enter the basketball team ");
}
Else if (hight>=175)//-- -- -- -- -- -- -- -- else has implied hight<180, so you can put this condition removed --
{
Printf (" xiaoming can enter the basketball reserve ");
}
The else//-- -- -- -- -- - the else already implied hight<175, so you can remove the this condition
{
Printf (" xiao Ming can't enter the basketball team ");
}
return 0;
}

C + + environment debugging VS2015

CodePudding user response:

Thank you, but why the last else don't add the if and the conditional word to add; No.?

CodePudding user response:

In front of all understand, but still axis here,,,

CodePudding user response:

If else if else
If is the first condition judgment
Else if judging is behind of the different situation, but this judgment condition is not so the rest of the circumstance of
Else the end is not a condition, he terms of default is ruled out outside the rest of the conditions listed above
C no act of usage, but through && | | connection is one and one is or

CodePudding user response:

Ok, thank you

CodePudding user response:

If the judge to write separately
  • Related