62.5k views
0 votes
You are tasked with creating a mileage calculator to calculate the amount of money that should be paid to employees. The mileage is computed as follows An amount of .25 for each mile up to 100 miles An amount of .15 for every mile above 100. So 115 miles would be (.25 * 100) + (.15 * 15) This can all be coded using a mathematical solution but I want you to use an if / else statement. Here is how you are to implement it: If the total miles input is less than or equal to 100 then simply calculate the miles * .25 and output the amount otherwise compute the total amount for all miles mathematically. Input: Total number of miles Process: dollar amount owed for miles driven Output: Amount of money due * Please note that you should simply do calculations within the if and else statements. This mean no cin or cout within if or else. Do it afterward.

1 Answer

2 votes

Answer:

Desired C++ Program with proper comment is given below

Step-by-step explanation:

#include<iostream>

using namespace std;

//main function

int main()

{

int totalMiles = 0;

int remainingMiles = 0;

double amt = 0;

//taking input from user regarind total miles

cout<<"Enter the total miles: "<<endl;

cin>>totalMiles;

//if-else condition to do the calculation

if(totalMiles<=100)

{

amt = totalMiles*.25;

}

else

{

remainingMiles = totalMiles - 100;

amt = 100*.25 + remainingMiles*.15;

}

cout<<"The total amount is: "<<amt<<endl;

}

User Ttsiodras
by
5.3k points