Write a C program to compute the car parking fee based on these rates: first 2 hour SR1 per hour, the following hours is SR2 per hour. Example, parking fee of 4 hours is (SR1 x 2) + (SR2 x 2) = SR6
I now that main is %100 wrong but I don now how to do it ... So,I need your help !?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <stdio.h>
int main (void)
{
int a=1,SR;
printf("enter hour to compute the car parking:");
scanf("%d",&a);
if(a<=2){
SR=a*1;
printf("%d SR\n",SR);}
elseif(a>2)
{
SR=(a*1)+(a*2);
printf("%d SR\n",SR);
}
}
In your else statement, since you know that a is bigger than 2, you know that you must pay SR1 x 2 and that you must add the remaining number of hours at SR2 price. so it would be something like this:
SR = 2*1 + (a-2) * 2; // 2 hours at SR1 per hour and the rest at SR2 per hour
Of course, I would advice you to use variables to store the prices.