LAB5 Final Report
LAB5 Final Report
Laboratory Activity 5
Getting Started
By
MATERIALS
1. VSCode,
2. Laboratory Manual
3. Online sources for formulas
1. Create a program that will determine the earthquakes damage from the given
richter scale:
● Add the include stdio.h and include int main in the first and second line,
respectively.
● Below the int main is the declaring variable as float.
● Use printf for the user to input the level of damage.
● Below printf is scanf so that the input can be an integer
● The program will determine the statement from the given earthquake
damage level with if, else if, and else statement from the following:
■ if level < 5.0 = Little or no damage
■ else if level >= 5.0 to <= 5.5 = Some damage
■ else if level > 5.5 to <= 6.5 = Serious damage
■ else if level > 6.5 to <= 7.5 = Disaster
■ else printf(“Catastrophe”)
● The last line will be the return 0
2. Create a program with the goal of combining three calculations into one program,
first one is to convert miles to kilometers, second is to convert pounds to
kilograms, and the third is to convert Fahrenheit to Rankin.
1
● First we include stdio.h
● Then create the main function int main()
● Then we declared the int variables choice, case1, case2, case3 and then the
float variables result1, result2, result3
● After which we used printf to display the menu prompting and informing
the user on the three functions and each of their responding call numbers
● If 1 it’s the conversion of miles to kilometers, if 2 pounds to kilograms, and
if 3 it’s Fahrenheit to Rankin
● Assigning the variable choice we use scanf for the user to input their choice
● Using switch-case statements to detect their choice between one to three,
we use printf to display what they have chosen and for them to input their
given value
● Using scanf we assign the variables case1 if they choose 1, case2 if they
chose 2, then case3 if they chose 3,
● In the same manner as above we use variables result1, result2, and result3
we perform the formulas:
○ result1 = (case1 * 1.6093440)
○ result2 = (case2 * 2.205)
○ result3 = (case3 + 459.67)
● Printf the variables result1, result2, result3 respectively in respect of their
choice earlier
3. Create a program that will determine if the person is short, average or tall with
their height centimeter:
● First is to add the include stdio.h in the first line
● Below the stdio.h is the int main
● Then, declare the variable height as float
● Use printf so that the user may be prompted to input their height in
centimeters
● Below the printf is the scanf assigned to the variable height, so that the user
may input their height
● The program will determine the statement from the users’ inputted height
with if, else if, and else statements from the following:
■ if (height <= 152.4) = Your short bruh
■ else if ((height > 152.4) && (height <= 162.56)) = Your height is
average
2
■ else if ((height > 162.56 ) && (height <= 170.18)) = You are
considered tall in the philippines!!
■ else, Dude, you are too tall
● The last line will be the return 0
1. Example Problem 1:
3
2. Example Problem 2:
4
3. Example Problem 3:
5
RESULTS AND DISCUSSION (Include the screenshots and discussions per problem solution)
1.
In problem 1, we created a program that will determine how strong is the earthquake
level that is inputted by the user. Firstly, we added stdio.h in the first line. Then, we
6
declare variable level as float. Additionally, we use printf for the user to input the level of
the earthquake and then below it is the scanf so that the user input will be a float and
become variable level. Next, we use the if, else if, and else statements to determine if the
user inputted is little to serious damage. We then use the else if the level is greater than 7
so the output will be catastrophe. Lastly, the last line will be the return 0.
2.
For problem two we created a program that has the ability to perform three functions
first to convert miles to kilometers, the second to convert pounds to kilometers, and the
third which converts Fahrenheit to Rankin. We first did the basics like including stdio.h
and making the program inside the function int main there we declared numerous
7
variables, for the int variables we have choice, case1, case2, case3, and for the float
variables we have result1, result2, result3. After declaring the variables we start by using
printf and scanf functions to inform the user of the three function the program has and
what value they should input to use the one they desire, we use the variable choice as
their input on what they chose.
Using switch-case statements to determine if they input 1 as their choice they will be
prompted to input their given value to be converted in their choices’ context, the process
for number 1 using the variables case1 and result1 the formula for their choice is result1
= (case1 * 1.6093440), and the same for the 2nd and 3rd choices they will also be
prompted to input their given, and their formulas will respectively be result2 = (case2 *
0.453592) and result3 = (case3 + 459.67) after the processes the program then displays the
results of result1, result2, result3, depending on what they have chosen.
3.
8
In the last problem, we created a program that will determine if the user height input is
short, average, or tall. First, we add stdio.h in the first line. And then, we declare the
variable height as float. Next, we use the printf for the user input and below it is the
scanf to make it a float and also a variable which is the height. Furthermore, we use the
if, else if, and else statements to determine if the user input is short, average, or tall in
reference to the height in the philippines. We then use the else statement if the user is
too tall. Lastly, in the last line is the return 0.
In this activity, we were able to perform the tasks given to us leading us to enrich
our minds with the many possibilities that conditions can offer in programming, and
really increase the scope of the programs we can possibly develop and create in the
future, it also helped us understand already existing ones much deeper and see many
things in a different light.
REFERENCES
1.
9
2.
*/
#include <stdio.h>
int main(void)
// 1. Declare variables
10
// Your code here! (More declarations)
printf("========================\n"
"========================\n"
scanf("%d", &choice);
// 4. Decision
switch (choice)
case 1:
printf("You chose conversions from miles to km\n how many miles are we
converting?\n");
scanf("%d", &case1);
break;
case 2:
printf("You chose conversions from pounds to kg\n how many pounds are we
11
converting?\n");
scanf("%d", &case2);
break;
case 3:
printf("You chose conversions from deg. F to deg. R\n how many degrees of F are
we converting?\n");
scanf("%d", &case3);
break;
default:
// Exit
return 0;
3.
12
13