Answer to Question #287282 in C++ for koden

Question #287282

Suppose the Road Transport Department (JPJ) intends to introduce a new compound system for speeding offenses on highways throughout Malaysia. JPJ hires your company to create a program to calculate and display the amount of compound that the driver has to pay. The program should ask the user to enter the speed limit and the speed of the vehicle in km/h units. If the speed does not exceed the speed limit, the program should display the message ‘innocent driver’.





The amount of the fine is calculated using the following method:




The basic fine is RM100. If the speed of the vehicle exceeds the speed limit of 20km/h or more, the total fine is the basic fine plus RM10 for each km/h that exceeds the speed limit. If the speed of the vehicle exceeds the speed limit, but the difference is less than 20km/h, the total fine is the basic fine plus RM5 for each km/h that exceeds the speed limit. The maximum fine is RM500.





1
Expert's answer
2022-01-13T09:39:32-0500
#include <iostream>
using namespace std;








int main() {
	int speedLimit;
	int speedVehicle;
	cout<<"Enter the speed limit in km/h units: ";
	cin>>speedLimit;
	cout<<"Enter the speed of the vehicle in km/h units: ";
	cin>>speedVehicle;


	//If the speed does not exceed the speed limit, the program should display the message ‘innocent driver’.
	if(speedVehicle<speedLimit){
		cout<<"\n\ninnocent driver\n";	
	}else{
		int fine=100;
		//The basic fine is RM100. If the speed of the vehicle exceeds the speed limit of 20km/h or more, 
		//the total fine is the basic fine plus RM10 for each km/h that exceeds the speed limit. 
		int diff=speedVehicle-speedLimit;
		if(diff>=20){
			fine+=diff*10;
		}else{
			//If the speed of the vehicle exceeds the speed limit, but the difference is less than 20km/h, 
			//the total fine is the basic fine plus RM5 for each km/h that exceeds the speed limit. 
			fine+=diff*5;
		}
		//The maximum fine is RM500.
		if(fine>500){
			fine=500;
		}
		cout<<"\nThe total fine is: RM"<<fine<<"\n";
	}


	
	cin>>speedLimit;


	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