C # Statement--SELECT statement--if Else statement

Source: Internet
Author: User

If,else

If if, else is another meaning, if the condition is determined within the parentheses, if the condition is met, the IF statement executes the command and if it does not, the IF statement is not entered.

The basic format:

①if (...) Conditions are judged in parentheses
{
program code, arithmetic, etc.
}
②if (...) Conditions are judged in parentheses
{
program code, arithmetic, etc.
}
else//if the IF condition is not met, execute the code here
{
program code, arithmetic, etc.
}
③if (...) Conditions are judged in parentheses
{
program code, arithmetic, etc.
}
else if (...) Also, if the condition 2 is met, execute the following code
{
program code, arithmetic, etc.
}

Example: ⑴ input name, score judge whether pass, if more than 80 points output "you learn good, deserves praise!" ", if between 50-60 points, then the output" is a little bit, and then try again ", if less than 50 output" will be beaten by the second-male play JJ, female spanking. "

Console.Write ("Please enter your name:");
String xm = Console.ReadLine ();
Console.Write ("Please enter your score:");
Double CJ = Convert.ToInt32 (Console.ReadLine ());
if (cj<60)
{
Console.WriteLine (xm+ "classmate Failed");
if (CJ<50)
{
Console.WriteLine ("Backward will be beaten occasionally-men's play JJ, female spanking!");
}
Else
{
Console.WriteLine ("Just a little bit, try again!");
}

}
Else
{
Console.WriteLine (xm+ "Students Pass");
if (cj>80&&cj<100)
{
Console.WriteLine ("You are good at learning, praise!") ");
}
}
Console.ReadLine ();

⑵ Standard Weight: Men's weight = height -100±3, female weight = height -110±3;

Formula variants: Men's weight-height +100=±3, female weight-height +110=±3.

Console.WriteLine ("Welcome to the Quejinshaoliang center of weighing");
Console.Write ("Please enter your gender:");
string sex = Console.ReadLine ();
Console.Write ("Please enter your weight (kg):");
Double TZ = convert.todouble (Console.ReadLine ());
Console.Write ("Please enter your height (cm):");
Double sg = convert.todouble (Console.ReadLine ());
Double A = +, B = 110,s=0;
if (sex== "male")
{
s = tz-sg + A;
}
Else
{
s = tz-sg + b;
}
if (s>3)
{
Console.WriteLine ("You're too fat to lose weight");
}
else if (s<-3)
{
Console.WriteLine ("You are too thin, the wind blows Away");
}
Else
{
Console.WriteLine ("Standard Weight");
}

Console.ReadLine ();

⑶ Enter a year to determine if the leap years are in use.

Usually said: Four years a leap, a century does not leap, 400 years again leap. For example, 2000 is a leap year, and 1900 is common year.
Console.Write ("Please enter a year casually:");
int y = Convert.ToInt32 (Console.ReadLine ());
if (y%4==0&&y%100!=0| | y%400==0)
{
Console.WriteLine ("Leap Year");
}
Else
{
Console.WriteLine ("Common Year");
}
Console.ReadLine ();

Console.WriteLine ("Please output three number, compare size, and output maximum value");
Console.Write ("First number:");
int a1 = Convert.ToInt32 (Console.ReadLine ());
Console.Write ("second number:");
int a2 = Convert.ToInt32 (Console.ReadLine ());
Console.Write ("Third number:");
int a3 = Convert.ToInt32 (Console.ReadLine ());
if (A1>A2&&A1>A3)
{
Console.WriteLine ("Output Maximum:" +a1);
}
else if (A2>A1&&A2>A3)
{
Console.WriteLine ("Output Maximum:" + A2);
}
Else
{
Console.WriteLine ("Output Maximum:" + A3);
}
Console.ReadLine ();

Example of ⑸ marriage.

Console.WriteLine ("Beauty asks: do you have a deposit?") (with/Without) ");
string n1 = Console.ReadLine ();
if (N1 = = "has")
{
Console.WriteLine ("Beauty asks: Do you have a car?") (with/Without) ");
string n2 = Console.ReadLine ();
if (N2 = = "has")
{
Console.WriteLine ("Beauty asks: Do you have a house?") (with/Without) ");
string n3 = Console.ReadLine ();
if (n3 = = "has")
{
Console.WriteLine ("Beauty asked:" Tonight at home on my one, to in-depth communication ");
}
Else
{
Console.WriteLine ("Beauty asked: Hurry up to buy a house");
}
}
Else
{
Console.WriteLine ("Beauty asked: Hurry to buy a car");
}
}
Else
{
Console.WriteLine ("Poor B, roll thick ...");
}
Console.ReadLine ();

C # Statement--SELECT statement--if Else statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.