need help with some homework

my teacher has given me a assignment for c plus but im at my wits end here. im so frustrated! heres what he wants

You are tasked with creating a mileage caclulator 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

heres the code i have so far im so lost.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

  Put the code#include <iostream>


using namespace std;

int main()
{
	int miles;
	miles = 0;


	cout << "enter the amount of miles driven" << endl;
	cin >> miles;
	if (miles >= 100) 
	{
		cout << " you are owed 25.00" << endl;
	}
	else if (miles =115)
	{
		cout << "you are owed 27.00" << endl;
		cin >> miles;

	}

	



} you need help with here.
The keyword here is "calculate". You're not doing any calculations here. What your instructor is asking is to take two different actions in two different scenarios.

When the employee travels less than 100 miles he receives 25 cents for each mile.
Thus, you need to calculate the number of miles times 0.25

Otherwise (that is, in all other cases) he receives 100 miles times 25 cents PLUS the miles in excess of 100 times fifteen cents. Notice that you don't need another if here, just an else, because the employess either travels up to 100 miles or travels farther than that.

In code, this would be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main() {
    double miles = 0.0; //Double is a floating-point type. An employee could travel by, say, 50.45 miles
    cout << "Enter the amount of miles: ";
    cin >> miles;
    if (miles <= 100) {
        cout << "The employee is owed " << (miles * 0.25) << " USD." << std::endl;
    }
    else {
        double difference = miles - 100; //The excess amount of miles refunded at 0.15
        cout << "The employee is owed " << (100 * 0.25 + difference * 0.15) << " USD." << std::endl;
    }
    getchar(); //Waits for the user to press Enter before closing the application
    return 0; //C++ programs should ALWAYS return 0 if the program runs to completion successfully!
}

In case you have any other questions, feel free to ask.
Topic archived. No new replies allowed.