Not sure why the last bit of my code isn't working.

I'm trying to make a code to calculate a ride fare, but I'm getting hung up. When i run my program, everything after my if statements doesn't seem to be working. For some reason it just stops after the if statement. Why isn't it using my fare equation to output a fare? Side note: apparently, when finished, this code is supposed to implement two functions, so maybe that's part of the problem?

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
/* Bryan Kobashi
Lab 4 CIS 22A

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

using namespace std;

int main()
{
   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: ";
    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;
    cout << "Is this a surge trip? Enter Y for yes, and N for no: ";
    cin >> surge;

        if (surge == 'Y'){
            cout << "Enter the surge multiplier: ";
            cin >> multiplier;}


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;

fare = baseFare + (perMinute * minutes) + (perMile * distance);
cout << fare;
}

    }

Line 27: Should use getline(cin, name) so it can read white space for first and last name.

Line 63 and 64: It's a switch statement, so you would not be able to calculate fare since the program breaks after each case. Put it outside your switch statement.
Ah, such simple little mistakes. Thanks for your assistance!
Topic archived. No new replies allowed.