generated from nuwank7/IT1050-Tutorial-01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tute02.c
47 lines (34 loc) · 948 Bytes
/
Tute02.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*Exercise 2 - Selection
Write a program to calculate the amount to be paid for a rented vehicle.
• Input the distance the van has travelled
• The first 30 km is at a rate of 50/= per km.
• The remaining distance is calculated at the rate of 40/= per km.
e.g.
Distance -> 20
Amount = 20 x 50 = 1000
Distance -> 50
Amount = 30 x 50 + (50-30) x 40 = 2300*/
#include <stdio.h>
int main() {
//variable declaration
float distance, amount;
//inputs
printf("Enter the distance the van has travelled : ");
scanf("%f",&distance);
//if condition
if(distance < 0)
{
printf("There is an error");
}
else if(distance <= 30)
{
amount = distance * 50.00; //calculation the amount to be paid
printf("The amount to be paid is : %.2f",amount); //output
}
else if(distance > 30)
{
amount = (30 * 50) + ((distance - 30) * 40);
printf("The amount to be paid is : %.2f",amount); //output
}
return 0;
}