I can't find my mistake :/

I can't for the life of me figure out what isn't working properly. If you input m, then 105, the output should be "....17 dollars and 55 cents." Similarly, if you input t, then 53, the output should be "....9 dollars and 1 cent."

When I run the program, if I enter a number that will calculate the total at over a dollar, the cents portion of the output messes up.

PLEASE HELP!!!

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
 
using namespace std;
 
char get_equipment_type();
int get_rental_duration();
int compute_rental_cost(char type, int time);
void report_rental_cost(char type, int time, int price);
 
int main() {
 
//Display the words "Trail Rentals Cashiering Program, version 1.0 (c)
//Scott Pingleton, 2014" on the computer monitor.
cout << "Trail Rentals Cashiering Program, version 1.0" << endl;
cout << "(c) Scott Pingleton, 2014" << endl;
 
char type;      //type of equipment rented
int time;       //time in minutes of rental
int price;      //price of rental in cents
 
type = get_equipment_type();
time = get_rental_duration();
price = compute_rental_cost(type, time);
report_rental_cost(type, time, price);
 
//Display the words "Finishing Trail Rentals Cashiering Program, version
//1.0
cout << "Finishing Trail Rentals Cashiering Program, version 1.0" << endl;
}
 
//This function asks the user for the equipment type, and returns that type
//as either an 's' (for skateboard), 'i' (for inline skate), 't' (for
//touring bike), or 'm' (for mountain bike.
char get_equipment_type() {
        char userresponse;
        char type;
 
        //Display the words "Enter the type of rental, S(kateboard), I(nline
        //skate), T(ouring bike, or M(ountain bike):" on the computer monitor.
        cout << "Enter the type of rental," << endl;
        cout << "S(kateboard), I(nline skate), T(ouring bike), or M";
        cout << "(ountain bike): " << endl;
 cin >> userresponse;
        if ((userresponse == 's') || (userresponse == 'S'))
                type = 's';
        else if ((userresponse == 'i') || (userresponse == 'I'))
                type = 'i';
        else if ((userresponse == 't') || (userresponse == 'T'))
                type = 't';
        else
                type = 'm';
        return type;
        }
 
//This function asks the user for the duration of the rental, in minutes,
//and returns that number.
int get_rental_duration() {
        int userresponse;
        int time;
 
        //Display the words "Enter the duration of the rental in minutes:" on
        //the computer monitor.
        cout <<"Enter the duration of rental in minutes: ";
        cin >> userresponse;
        if ((userresponse > 0) && (userresponse < 721))
                time = userresponse;
        else
                time = 60;
        return time;
        }
 
//This function accepts the equipment type ('s', 'i', 't', or 'm') and the
//duration of the rental, and returns the cost of the rental in dollars (if
//any) and cents (if any)
int compute_rental_cost(char type, int time) {
        int price;
 
        if ((type == 's') || (type == 'i'))
                price = time * 15;
        else if (type == 't')
                price = time * 17;
        else if ((type == 'm') && (time <= 60))
                price = 900;
        else
                price = 900 + ((time - 60) * 19);
        return price;
        }

//This function accepts the equipment type ('s', 'i', 't', or 'm') and the
//total cost.  It will then convert the total cost of the rental to dollars
//(if any) and cents (if any), and display the information to the user in a
//well-formatted Englist language sentence.
void report_rental_cost(char type, int time, int price) {
        int dollarcost;
        int centcost;
 
        //Calculate the total amount of dollars (if any) and cents (if any)
        dollarcost = price / 100;
        centcost = price % 100;
 
                //Evaluate char type of 's', 'i', 't' and 'm' and return
                //the value of "skateboard", "inline skate", "touring bike",
                //or "mountain bike".
                if (type == 's')
                        cout << "skateboard";
                else if (type == 'i')
                        cout << "inline skate";
                else if (type == 't')
                        cout << "touring bike";
                else
                        cout << "mountain bike";
        cout << " rental will cost ";
                if ((dollarcost == 0) && (centcost > 0))
                        cout << centcost << " cents." << endl;
                else if ((dollarcost == 1) && (centcost > 0))
                        cout << dollarcost << " dollar and " << centcost <<
                        cout << " cents." << endl;
                else if ((dollarcost > 0) && (centcost == 0))
                        cout << dollarcost << " dollars." << endl;
                else if ((dollarcost > 0) && (centcost == 1))
                        cout << dollarcost << " dollars and " << centcost <<
                        cout << " cent." << endl;
                else
                        cout << dollarcost << " dollars and " <<
                        cout << centcost << " cents." << endl;
        }
closed account (j3Rz8vqX)
Looks like your printing an address... Possibly a buggy report.

But! you also got some errors:

Line 113-125 have issues:

1
2
3
                        cout << dollarcost << " dollar and " << centcost <<//<<--See this?
                        cout << " cents." << endl;
//Repeat * 3; 


Try that first, it may possibly resolve all of your problems.
Actually, it will; unless other intentions are concealed.
Have a good day.
Last edited on
Topic archived. No new replies allowed.