Any thoughts

I am having issues getting this code to perform properly. Toward the end under the "//get answers" section, the program isn't adding in the vehiclDriverFare to the totalFare when I run. can't seem to figure it out.

Thanks


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

using namespace std;

int main()
{
	//declare variables

	
	int driverAge = 0, seniors = 0, y = 0, n = 0;
	double vehicleLength = 0, totalFare = 0,seniorsMinusDriver = 0, vehicleDriverFare = 0, adultsMinusDriver = 0; 
	double youthsMinusDriver = 0, bikeRiders = 0, totalBikers = 0, totalAdults = 0, totalYouthSenior = 0;
	char response = 0, driverInfo = 0, vehicleHeight = 0;

	//Begin user input.
	
	cout << "Welcome to Oliver's fare calculator! " << endl;
	//assuming driver is an adult?  Can't someone between 16-18 drive onto the fairy?
	cout << "Are you driving a vehicle onto the ferry? (y/n) :  ";
	cin >> response;
	if ( response == 'n' )
		exit(0);
	cout << "Is the driver a senior citizen (65 or older), disabled? (y/n) :  ";
	cin >> driverInfo;
	cout << "How many passengers are in your vehicle? (excluding the driver)  ";
	cout << endl;
	cout << "Adults (age 19 - 64) :  ";
	cin >> adultsMinusDriver;
	cout << "Senior Citenzens (65 or older), or Disabled Persons:  ";
	cin >> seniorsMinusDriver;
	cout << "Youth (age 5 - 18) :  ";
	cin >> youthsMinusDriver;
	cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n)  ";
	cin >> vehicleHeight;
	cout << "How long is your vehicle in feet: ";
	cin >> vehicleLength;
	cout << "How many people in your group are traveling with a bicycle?  ";
	cin >> bikeRiders;
	cout << endl;

	//GET ANSWERS

        if (vehicleLength <= 14)
	{
			if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 36.05;
			if (vehicleHeight == 'y' && driverAge == 'n')
					vehicleDriverFare = 71.85;
			if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 29.55;
	}
	
	if (vehicleLength <= 22)
			{
				if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 45.00;
				if (vehicleHeight == 'y' && driverAge == 'n')
						vehicleDriverFare = 89.75;
				if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 38.50;
			}
	if (vehicleLength < 30)
			{
				if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 69.60;
			    if (vehicleHeight == 'y' && driverAge == 'n')
						vehicleDriverFare = 138.95;
				if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 69.60;
			}
	totalBikers = bikeRiders * 2.00;
	totalAdults = adultsMinusDriver * 12.95;
	totalYouthSenior = (youthsMinusDriver + seniorsMinusDriver) * 6.45; 
	totalFare = totalAdults + totalYouthSenior + vehicleDriverFare + totalBikers;

	cout << "Your total fare is $" << totalFare << ".  Thanks!  My Fare Calculator.  ";
	cout << endl << endl;

	cout << "I made it" << endl << endl;

	
	return 0;
driverAge is an integer. How can it ever be equal to 'n' or 'y' like you want it to be?

1
2
&& driverAge == 'n')
&& driverAge == 'y')


This will never be true, so your if statements will never be true, so vehivleDriverFare will always be 0.
Alright, I have changed the driverAge to char. I also deleted the unnecessary y, n, and senior identifiers. But inevitably still stuck...

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

using namespace std;

int main()
{
	//declare variables

	
	
	double vehicleLength = 0, totalFare = 0,seniorsMinusDriver = 0, vehicleDriverFare = 0, adultsMinusDriver = 0; 
	double youthsMinusDriver = 0, bikeRiders = 0, totalBikers = 0, totalAdults = 0, totalYouthSenior = 0;
	char response = 0, driverInfo = 0, vehicleHeight = 0, driverAge = 0;

	//Begin user input.
	
	cout << "Welcome to Oliver's fare calculator! " << endl;
	//assuming driver is an adult?  Can't someone between 16-18 drive onto the fairy?
	cout << "Are you driving a vehicle onto the ferry? (y/n) :  ";
	cin >> response;
	if ( response == 'n' )
		exit(0);
	cout << "Is the driver a senior citizen (65 or older), disabled? (y/n) :  ";
	cin >> driverInfo;
	cout << "How many passengers are in your vehicle? (excluding the driver)  ";
	cout << endl;
	cout << "Adults (age 19 - 64) :  ";
	cin >> adultsMinusDriver;
	cout << "Senior Citenzens (65 or older), or Disabled Persons:  ";
	cin >> seniorsMinusDriver;
	cout << "Youth (age 5 - 18) :  ";
	cin >> youthsMinusDriver;
	cout << "Is your vehicle over 7 feet, 6 inches in height? (y/n)  ";
	cin >> vehicleHeight;
	cout << "How long is your vehicle in feet: ";
	cin >> vehicleLength;
	cout << "How many people in your group are traveling with a bicycle?  ";
	cin >> bikeRiders;
	cout << endl;

	if (vehicleLength <= 14)
	{
			if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 36.05;
			if (vehicleHeight == 'y' && driverAge == 'n')
					vehicleDriverFare = 71.85;
			if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 29.55;
	}
	
	if (vehicleLength <= 22)
			{
				if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 45.00;
				if (vehicleHeight == 'y' && driverAge == 'n')
						vehicleDriverFare = 89.75;
				if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 38.50;
			}

	if (vehicleLength < 30)
			{
				if (vehicleHeight == 'n' && driverAge == 'n')	
					vehicleDriverFare = 69.60;
			    if (vehicleHeight == 'y' && driverAge == 'n')
						vehicleDriverFare = 138.95;
				if (vehicleHeight == 'n' && driverAge == 'y')
						vehicleDriverFare = 69.60;
			}

	totalBikers = bikeRiders * 2.00;
	totalAdults = adultsMinusDriver * 12.95;
	totalYouthSenior = (youthsMinusDriver + seniorsMinusDriver) * 6.45; 
	totalFare = totalAdults + totalYouthSenior + vehicleDriverFare + totalBikers;

	cout << "Your total fare is $" << totalFare << ".  Thanks!  ~Oliver's Fare Calculator.  ";
	cout << endl << endl;

	cout << "I made it" << endl << endl;

	
	return 0;
}
Again, why would driverAge ever be 'n' or 'y'? Just pause a moment and think. You never ever use that variable, it is equal to whatever you initialize it to, you never change its value, you never use it.
Topic archived. No new replies allowed.