0% found this document useful (0 votes)
39 views3 pages

If Else Practice Statements

The document discusses several if/else practice problems including: 1. Writing a program to determine if a number is odd or even using modulus. 2. Finding the smallest and largest of two or three numbers. 3. Creating a BMI calculator that reads weight and height to calculate BMI and classify it. It also contains questions to identify errors in code snippets, determine the output of code with if/else statements, and predict the output based on different variable values in an if statement.

Uploaded by

maimoona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

If Else Practice Statements

The document discusses several if/else practice problems including: 1. Writing a program to determine if a number is odd or even using modulus. 2. Finding the smallest and largest of two or three numbers. 3. Creating a BMI calculator that reads weight and height to calculate BMI and classify it. It also contains questions to identify errors in code snippets, determine the output of code with if/else statements, and predict the output based on different variable values in an if statement.

Uploaded by

maimoona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

If else practice statements:

(Odd or Even) Write a program that reads an integer and determines and prints whether it’s
odd or even.
[Hint: Use the modulus operator. An even number is a multiple of two. Any multiple of two
leaves a remainder of zero when divided by 2.]

Find the smallest and largest among two numbers

Find the smallest and largest among three numbers

(BMI) Create a BMI calculator application that reads the user’s weight in pounds and
height in inches (or, if you prefer, the user’s weight in kilograms and height in meters),
then calculates and displays the user’s body mass index. Also, the application should
display the following information from the Department of Health and Human
Services/National Institutes of Health so the user can evaluate his/her BMI.

BMI = weight In Kilograms


_________________________
heightInMeters x heightInMeters

BMI VALUES:
Underweight: less than 18.5
Normal: between 18.5 and 24.9
Overweight: between 25 and 29.9
Obese: 30 or greater

Question 1.
Identify whether the following lines of code contain errors or not, also state the error
your compiler generates.
1a.
static void Main(string[] args)
{
int num=5;
If (num=9)
{
Console.WriteLine(“the number is {0}”, num);
}
else
{
Console.WriteLine(“the number is {0}”, num);
}
}
1b.
static void Main(string[] args)
{
If (2)
{
Console.WriteLine(“******”);
}
else
{
Console.WriteLine(“######”);
}
}
1c.
static void Main(string[] args)
{
If (-45)
{
Console.WriteLine(“******”);
}
else
{
Console.WriteLine(“######”);
}
}
Dangling if-else problem:
State the output of the code
1.
static void Main(string[] args)
{
int x = 9, y = 11;
if (x < 10)
if (y > 10)
Console.WriteLine("*****");
else
Console.WriteLine("#####");
Console.WriteLine("$$$$$");
}
2.
static void Main(string[] args)
{
if (x < 10)
if (y > 10)
Console.WriteLine("*****");
else
Console.WriteLine("#####");
Console.WriteLine("$$$$$");
}

3. Predict the output if


3a. x=5,y=8 and
3b. x=5,y=7

if (y == 8)
if (x == 5)
Console.WriteLine("@@@@@");
else
Console.WriteLine("#####");
Console.WriteLine("$$$$$");
Console.WriteLine("&&&&&");

You might also like