Answer to Question #135224 in C++ for agym

Question #135224
Based on the problems given, write a program using selection control structure.


1. 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.
1
Expert's answer
2020-09-27T23:44:13-0400
#include <iostream>

using namespace std;

int main()
{
    int hours;
    double totalCost ;
    cout << "Enter the number of hours of car parking : ";
    cin >> hours ;
    if(hours > 1){
        totalCost = 2.0 + (hours - 1) * 1.0 ;
    }
    else if(hours == 1){
        totalCost = 2.0;
    }
    else{
        totalCost = 0 ;
    }
    cout << "The total cost is : RM " << totalCost << endl ;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS