ENG3202 Lab Report 2 - User Input
ENG3202 Lab Report 2 - User Input
ENG3202
Name: Fakhrul Hakim bin Anwar
No. Matrik: 228724
OCTOBER 30
COMPUTER PROGRAMMING
1
ENG3202 Computer Programming 2024-2025 LAB 2: USER INPUT
Question 1
Write a program that will prompt the user to input the height, length and width of
a box in centimeters. From the user input the program must calculate and display
box’s volume.
Pseudocode:
1. Start the program
2. Declare your variable Height, length , width and Volume in float value
3. Put the Height Value
4. Put the length Value
5. Put the width Value
6. State the Volume formula ‘ Volume = Height x length x width ‘
7. Display the value of the Volume in float value
8. End Program.
Flow Chart
2
ERROR
Debug
Output
3
4
Question 2
Write a program that simulates an odometer. The user inputs the speed (in kmph)
and time the vehicle has traveled (in seconds!!). From the user input, the program
must calculate and display the distance traveled. The program must also display
the speed and time entered by the user.
Pseudocode:
1. Start the Program
2. Declare your Variable Speed, Time and Distance as Float Value
3. Put the value of Speed in kmph
4. Put the value of Time in seconds
5. Calculate the Distance by using the formula ‘ Distance = Speed x time/3600
‘
6. Display the value of the Distance
7. End of program
5
Flow Chart
6
Error
At this error I got the output 0.000 where I shouldn’t have gotten that result. I
notice that I use %f for Distance where it has been stated that its integer.
7
Debug
Output
8
Question 3
Given by a user are the x- and y- coordinates of two points in a plain: (x1, y1) and
(x2,y2). Write a C program that will compute and print the distance between
these two points using given below.
𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 = √(𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐
Pseudocode:
1. Start the program.
2. Declare your Variable X1 , Y1, X2, Y2, and Distance, as Float Value.
3. Print ‘This program will calculate the distance between two points (x1,y1)
and (x2,y2) ‘
4. Put the value of X1
5. Put the value of Y1
6. Put the value of X2
7. Put the value of Y2
8. Calculate the value of distance using the equation
𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 = √(𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐
9. Print the Value of Distance.
10.End of Program
9
Flow Chart
10
Error
Debug
11
Output
12
Discussion and Analysis
1) For question 1 , The Program was conducted to find the Volume of a Box .
By putting scanf, User can put any Value of height length and width of any
variation of Boxes to find the Volume of it. Volume was found by using
the formula Volume = height x length x width . From my Output picture
given the volume is 8 when height = 2 , length=2 and width=2 meaning
the program works as it intended to. The program was successful after 3
times compiling it . I got some error like Forgot to put ‘;’ at the end of
each command and some spelling error
13