Not getting desired Output

Hi, I have an assignment to create a code that tracks the amount of trips that can be taken on a set of tires before they wear out. For now, my input is 8 miles and 14 inch radius for the wheels. The correct output is supposed to be 607 trips, yet I am receiving 557 trips. I've looked at the calculations, but I'm not sure of what I'm doing wrong. My output is:
How far is a one-way trip in miles from your house to the Slate Rock and Gravel Quarry? 8
What size tires would you like to purchase (12, 14, or 16-inch radius)? 14
The distance you entered for a round-trip, in inches, is 1013760
The circumference of the tire you selected is 87.9646
The amount of total trips you can make is 557 trips.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 #include <iostream>
#include <cmath>

using namespace std;


constexpr int inches_per_mile{63360};
constexpr double rate_of_wear{0.0000005};

int miles_to_inches(int miles)
{
    int inches;
    inches = miles * inches_per_mile * 2;
    return inches;
}

double radius_circumference(int radius)
{
    double circumference;
    circumference = 2 * M_PI * radius;
    return circumference;
}

int num_trips(int circumference, int inches)
{
    int numOfTrips, tireRadius, trips, numOfRotations;
    double radiusWear, wearPerTrip;
    numOfRotations = inches / circumference;
    wearPerTrip = numOfRotations * rate_of_wear;
    tireRadius = circumference / (2 * M_PI);
    radiusWear = tireRadius * .25;
    numOfTrips = radiusWear / wearPerTrip;

    return numOfTrips;
}

int main ()
{
   int miles, inches, tireRadius, totalTrips, trips;
   double circumference;
   
    cout << "How far is a one-way trip in miles from your house to the Slate Rock and Gravel Quarry? ";
    cin >> miles;
    cout << endl;

    cout << "What size tires would you like to purchase (12, 14, or 16-inch radius)? ";
    cin >> tireRadius;
    cout << endl;

    

    inches = miles_to_inches(miles);
    circumference = radius_circumference(tireRadius);
    totalTrips = num_trips(circumference, inches);
    

   

   cout << "The distance you entered for a round-trip, in inches, is " << inches;
   cout << endl;

   cout << "The circumference of the tire you selected is  " << circumference;
   cout << endl;

   cout << "The amount of total trips you can make is " << totalTrips << " trips. ";
   cout << endl;

   return 0;
}
Last edited on
Where are your code tags?
Sorry, thanks for pointing that out.
most likely if its not what you expect, you have messed up mixing integers and doubles, and some piece of math has truncated a decimal that is messing up the result. should numOfRotations be a double? It is assigned a division result.

lets see... there are 5280 feet in a mile. there are 12 inches per foot. that is 63360, * 8 = 506880 inches in an 8 mile ride.
why does have *2 in inches per mile? round trip? If so, its right. I see what you did there, but its not well named (its not inches to mile conversion, its doing something else).

tire-radius could be corrupted from int/double. When I run it with your example input and print tire-radius in the function, at line 30, I get 13 instead of 14 due to floating point round off... !!
Last edited on
When I changed numOfRotations to a double, it had no impact on the output. It was still the same.
The *2 is to make it round-trip, instead of one-way.
So could I possibly use float in order to get the correct tire-radius?
Thank you very much, I figured it out due to the information you provided.
Topic archived. No new replies allowed.