program question

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
#include <iostream>
#include <iomanip>

using namespace std;
//for single customers
const double single_first_30_minutes = 7.00;
const double single_after_30_minutes = 1.50;

//for couple customers
const double couple_first_30_minutes = 10.50;
const double couple_after_30_minutes = 2.50;

//for group customers
const double group_first_30_minutes = 16.00;
const double group_after_30_minutes = 4.00;

//To figure out if time is less then or equal to 30 minutes
const double mintime = 30;
const double mintimetwo = 20;
const double mintimethree = 15;

//To figure out if customer needs to pay an additional $50 fee
const double maxtime = 60;

int main()
{
char travelerType;
int time;
double total;

 cout << fixed << showpoint;                     
 cout << setprecision(2);

cout << "This program will calculate your ticket."<<endl<<endl;

cout << "Please enter passenger type: S or s (single), " 
     << "C or c (couple), "
     << "G or g (group). "<<endl;
cin >> travelerType;
cout << endl;

while (travelerType!='stop')
{

if (travelerType=='S' || travelerType=='s')
{                      
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;

      if (time <= mintime)
      {         
      cout << "Your total is: $7.00" << endl;
      }
      else if (time > mintime)
      {
      total = single_first_30_minutes + (single_after_30_minutes * time);
      cout << "Your total is: $" << total << endl;
      }
} //closes first if statement
if (travelerType=='C' || travelerType=='c')
{         
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;
             
      if (time < mintime)
      {         
      cout << "Your total is: $10.50" << endl;
      }
      else if (time > mintimetwo)
      {
      total = couple_first_30_minutes + (couple_after_30_minutes * time);
      cout << "Your total is: $" << total << endl;
      cout << endl;
      }
      
} //closes second if statement
if (travelerType=='G' || travelerType=='g')
{         
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;
             
      if (time < mintimethree)
      {         
      cout << "Your total is: $16.00" << endl;
      }
      else if (time > mintimethree && time > 30)
      {
      total = group_first_30_minutes + (group_after_30_minutes * time) + 50;
      cout << "Your total is: $"<< total << endl;
      cout << endl;
      }
      else if (time > mintimethree)
      {
      total=group_first_30_minutes+(group_after_30_minutes * time);
      cout << "Your total is: $" << total << endl;
      cout << endl;
      }
} //closes third if statement
else if (travelerType=='stop');

else 
     cout << "Your input is invalid, please try again.";
} //End While loop

cout << "Stop has been entered; program exited.  Thanks for using the fare calculator!"<<endl;
    system ("pause");
    return 0;
}

I'm not going to lie, this is school work but it is about 90% done, there are some problems I cannot find in the program such as the else statement executing reguardless of the if statements being true, and an infinite while loop when the breaking word 'stop' is entered. I completely understand if you cannot help, but I would appreciate any help given and will +rep everyone who helps. I'm not a complete novice programmer, but I've been pulling my hair out for 2 days now and cannot for the life of me find the mistake...
Last edited on
Could you use [code][/code] tag and indentation please?
sorry, fixed. Thanks for looking.
The while loop: I see that travelerType is a char, which means it holds one character. So it can't ever hold "stop", a string. You also cannot put a string inside single quotes like you have there; single quotes are for "single character constants" only, not strings. String literals use double quotes.

I have to say, though, your indentation could use some work. Indent everything in a block; that might help you see better which else's connect to which if's, I imagine that is the problem with your else statement.
Yeah I don't know what I was thinking with the char holding 4 characters.. Thanks for the help!
Topic archived. No new replies allowed.