2014.8.16 if statement

Source: Internet
Author: User

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! ");

}

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.