A car park has the following charges. The 1st hours cost RM2.00. The sub sequent hours cost RM1.00 per hour. Write a program for this problem.
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
float hours;
cout<<"Enter hours: ";
cin>>hours;
float cost;
if(hours<=1){
cost=hours*2.0;
}else{
cost=2.0+(hours-1);
}
cout<<"Cost is: RM"<<cost<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment