Statement
If statement
There are several types of data:
Example:
(1) determine whether to pay taxes based on monthly income
Console. Write ("Enter your monthly income (RMB ):");
Double money = convert. todouble (console. Readline ());
If (money >=3500)
{
Console. writeline ("Please pay taxes ");
Console. writeline ("Thank you for your cooperation! ");
}
Else
{
Console. writeline ("continue to work ");
Console. writeline ("Thank you for your cooperation! ");
}
(2) Determine whether the woman is married to the man based on the house, money, and Ability
Try
{
Console. Write ("Do you have a room (true/false )? ");
Bool House = convert. toboolean (console. Readline ());
If (House = true)
{
Console. writeline ("Oh, let's get married !!!! ");
}
Else
{
Console. Write ("are you rich (true/false )? ");
Bool money = convert. toboolean (console. Readline ());
If (money = true)
{
Console. writeline ("Buy a house first and then get married! ");
}
Else
{
Console. Write ("are you competent (true/false )? ");
Bool ability = convert. toboolean (console. Readline ());
If (ability = true)
{
Console. writeline ("Cool, please make some money first! ");
}
Else
{
Console. writeline ("Get out !!!!!! ");
}
}
}
}
Catch
{
Console. writeline ("input error! ");
}
(3) Calculate the root of ax ^ 2 + bx + c = 0
Try
{
Console. writeline ("Calculate the root of ax ^ 2 + bx + c = 0 ");
Console. Write ("A = ");
Int A = convert. toint32 (console. Readline ());
Console. Write ("B = ");
Int B = convert. toint32 (console. Readline ());
Console. Write ("c = ");
Int c = convert. toint32 (console. Readline ());
If (A = 0)
{
Console. writeline ("not a quadratic equation! ");
}
Else
{
Int Delta = B * B-4 * a * C;
If (delta> 0)
{
Console. writeline ("X1 = {0}, X2 = {1}", (-B + math. SQRT (DELTA)/2 * A), (-B-math. SQRT (DELTA)/2 * ));
}
Else if (delta = 0)
{
Console. writeline ("x =" +-B/2 * );
}
Else
{
Console. writeline ("the equation has no real root! ");
}
}
}
Catch
{
Console. writeline ("incorrect input ");
}
(4) Input height and weight to determine the health status
Try
{
Console. writeline ("Enter height and weight to determine health ");
Console. Write ("Enter Gender :");
String sex = console. Readline ();
Console. Write ("Enter Height :");
Int Height = convert. toint32 (console. Readline ());
Console. Write ("Enter weight :");
Int Weight = convert. toint32 (console. Readline ());
If (sex = "male ")
{
Int num = height-100-weight;
If (Num> 3)
{
Console. writeline ("thin ");
}
Else if (Num> =-3 & num <= 3)
{
Console. writeline ("normal ");
}
Else
{
Console. writeline ("Overweight ");
}
}
Else if (sex = "female ")
{
Int num1 = height-110-weight;
If (num1> 3)
{
Console. writeline ("thin ");
}
Else if (num1> =-3 & num1 <= 3)
{
Console. writeline ("normal ");
}
Else
{
Console. writeline ("Overweight ");
}
}
}
Catch
{
Console. writeline ("incorrect input! ");
}