Problem 3
Problem 3
Question
The following table shows the car parking rate according to parking duration.
PARKING DURATION First hour (1st hour) The next 3 hours (2nd, 3rd and 4th hours) The next 2 hours (5th and 6th hours) The next 4 hours (7th, 8th, 9th and 10th hours)
Write a program that obtains the duration of parking in hour from the user. Assume that the parking duration cannot exceed 10 hours. Display the output as the following format.
Flowchart
START
read hr
(hr<=1) and (hr>0) F (hr>=2) and (hr<=4) F (hr>=5) and (hr<=6) F (hr>=7) and (hr<=10)
RM 1
END
Source code :
#include<iostream> #include<cmath> using namespace std; int main() { cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<"\n\tSyarikat Parking Mesra Sdn. Bhd"; cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++";
float hr, sub, tot_c; cout<<"\n\tDuration of Parking \t:"; cin>>hr; if ((hr<=1)&&(hr>0)) { cout<<"\tTotal Charges \t\t:RM 1 "; } else if ((hr>=2)&&(hr<=4)) { sub = (hr-1); tot_c = (sub * 0.5) + 1; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }
else if ((hr>=5)&&(hr<=6))` { sub = hr-4; tot_c = (sub*0.4) + 2.5; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }
else if ((hr>=7)&&(hr<=10)) { sub = hr-6; tot_c = (sub*0.3) + 3.30; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }
else cout<<"\n\t\tError! You Have Reached The Quota."; cout<<"\n\n\t\t\t==Thank you=="; cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++";
Output