You are on page 1of 10

LAB-1(If-Else Statements/Nested Conditional

Statements
THEORY
The ability to control the flow of your program, letting it make decisions on what code to execute,
is valuable to the programmer. The if-statement allows you to control if a program enters a section
of code or not based on whether a given condition is true or false. One of the important functions of
the if-statement is that it allows the program to select an action based upon the user's input. For
example, by using an if-statement to check a user entered password, your program can decide
whether a user is allowed access to the program. Without a conditional statement such as the if-
statement, programs would run almost the exact same way every time. If-statements allow the flow
of the program to be changed, and so they allow algorithms and more interesting code.
THEORY
EXAMPLE 1:

int age, height;


cin >> age;
cin >> height;
if(height <= age)
{ cout << "Your height is less than or equal to your age!";
}
THEORY
{
cout << "Your height is equal to your age!";
}
else if(height < age)
{
cout << "Your height is less than your age!";
}
else if(height > age)
{
cout << "Your height is greater than your age!";
}
else
{
cout << "Something has gone seriously wrong here!";
}
MACHINE PROBLEMS
MACHINE PROBLEM 1
MACHINE PROBLEMS
MACHINE PROBLEMS

MACHINE PROBLEM 2
Engineering Equations
Research about two complex engineering equations related to your field. Equations should have at
least. four variables
Program shows a formula selection screen that allows the user to select a formula.
• Formula selection screen allows the user to quit the program.
• Program asks the user what variable in the equation to compute.
• Variable selection screen allows the user to go back to the formula selection screen.
• Program asks values for input variables and computes the selected variable.
MACHINE PROBLEMS

MACHINE PROBLEM 2
• Program goes back to the variable selection screen. User can select another variable to compute or
select to go back to the formula selection screen.
• Program goes back to the formula selection screen.
• Do not use goto and/or global variables (this rule applies to all suceeding final programs).
MACHINE PROBLEMS

MACHINE PROBLEM 2
Test Walkthrough
1. Select a formula from the formula selection screen.
2. Select a variable from the variable selection screen.
3. Compute for the variable. Provide at least 2 sets of test data per variable.
4. Enter an invalid choice at the variable selection screen.
4. Repeat step 2 until all variables are computed.
5. Repeat step 1 until all formulas are demonstrated.
6. Enter an invalid choice at the formula selection screen.
7. Quit the program.
MACHINE PROBLEMS

NOTE :
FOR VERY MACHINE PROBLEM , THERE WILL BE A CORRESPONDING PRINTSCREEN
OUTPUTS FOR THE NECESSARY REQUIREMENTS BASED ON THE GIVEN PROBLEM.
THANK YOU!!!!

You might also like