I must be making a few simple mistakes, but i can't find them and it's making me.... AAAHHHHHHHH!!!!!!!!!!!! **Smash computer

So I'm trying to write a code that calculates ride fares and it's just about complete, but there's a small problem... when I run this code the final function doesn't do anything, so the program just ends. If I put the output in the second function it works fine. Also, at some point before tinkering with it I was able to get the last function to print the cout, but I was unable to use the string, name, in that section. Any help pleease?


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

/* Bryan Kobashi
bryan.kobashi@gmail.com
Lab 4 CIS 22A

*/
#include <iostream>
#include <iomanip>

using namespace std;

double fareCalc (double minutes, double distance, double multiplier, double baseFare, double perMinute, double perMile, double minimum);
void output (double fare);

int main()
{
 // define variables
   string name;
   double minutes;
   double distance;
   char surge;
   char option;
   double multiplier;
   double baseFare;
   double perMinute;
   double perMile;
   double minimum;
   double fare;

    cout << "Enter first and last name then press enter: ";
    //Make sure to use getline since it's two words.
    getline (cin, name);
    cout << "Enter the length of your ride in minutes: ";
    cin >> minutes;
    cout << "Enter the distance of your trip in miles: ";
    cin >> distance;
    cout << "Enter your budget option, S for SUV, X for budget, and L for luxury: ";
    cin >> option;
    option = (char) toupper(option);
    cout << "Is this a surge trip? Enter Y for yes, and N for no: ";
    cin >> surge;
    surge = (char) toupper(surge);

//Use switch (option) for different car options.

switch (option)
{
case 'L':
    baseFare = 5.00;
    perMinute = 0.50;
    perMile = 2.75;
    minimum = 10.55;
    break;
case 'S':
   baseFare = 15.00;
    perMinute = 0.90;
    perMile = 3.75;
    minimum = 25.00;
    break;
case 'X':
     baseFare = 2.00;
    perMinute = 0.22;
    perMile = 1.15;
    minimum = 6.55;
    break;
}
        if (surge == 'Y'){
            cout << "Enter the surge multiplier: ";
            cin >> multiplier;
        }
fare = fareCalc(minutes, distance, multiplier, baseFare, perMinute, perMile, minimum);
return 0;
        }


double fareCalc (double minutes, double distance, double multiplier, double baseFare, double perMinute, double perMile, double minimum)
{
    double fare;
    fare = (baseFare * multiplier) + (perMinute * minutes) + (perMile * distance);
if (fare < minimum){
    fare = minimum;}
    else{
        fare = fare;
   
    return fare;
    }
}

void output(double fare)
{
    cout << "Fare " << setprecision(2) << fixed;
    cout << "Rider's name" << name << endl;
    cout <<  "Total: $" << fare;
}



Line 72 : Your function main returns but you never actually called your function output().

Should be :

1
2
output(fare);
return 0;
Last edited on
That was it! Thank you so much!
Topic archived. No new replies allowed.