Help with running total, functions and mod (HW Assignment)

I'm trying to display the average of the running total of tickets issued. I'm not sure if its a logic error or not.

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
127
128
129
130
131
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


void programInfo();
void licenseP(string & plateNumber);
void inputData(double & vehicleSpeed, double & speedLimit);
void processData(double vehicleSpeed, double & ticketAmount, double & speedOver, double speedLimit, double ticketTotal, string plateNumber);
void displayResults(double ticketCounter, double totalVehicles, double ticketAmount, double percent, double ticketTotal);


int main()
{// Variables
	double vehicleSpeed = 0;
	double ticketAmount = 0;
	double speedOver = 0;
	double speedLimit = 0;
	double percent = 0;
	double ticketTotal = 0;
	string plateNumber = " ";
	string sentinel = "NOMORE";

	programInfo();
	cout << fixed << showpoint << setprecision(2);
	licenseP(plateNumber);

	int ticketCounter = 0; // Set counter
	int totalVehicles = 0; // Set counter

						   // While loop
	while (plateNumber != sentinel)
	{
		inputData(vehicleSpeed, speedLimit);
		processData(vehicleSpeed, ticketAmount, speedOver, speedLimit, ticketTotal, plateNumber);

		// Use the if/else statement to count the vehicles
		// being ticket and the total of vehicles pull over
		// according to the ticket amount.
		if (ticketAmount == 0)
			totalVehicles++;
		else if (ticketAmount > 0)
		{
			totalVehicles++;
			ticketCounter++;
		}

		
		

		cout << "\n";
		licenseP(plateNumber);

	}
	


	displayResults(ticketCounter, totalVehicles, ticketAmount, percent, ticketTotal);

	return 0;
}

void programInfo()
{
	cout << "AHP Program by Jeffrey Sirimaturos please follow the instructions as told. Thank you." << endl << endl;
	cout << "Enter the license plate number, vehicle's current speed, and speed limit in the zone." << endl;
	cout << "To stop repeating the process please enter 'NOMORE'." << endl;
	cout << "\n";

}

void licenseP(string & plateNumber)
{
	cout << "Enter a license plate number  --->" << setw(8);
	cin >> plateNumber;
}



void inputData(double & vehicleSpeed, double & speedLimit)
{
	cout << "Enter current vehicle's speed --->" << setw(8);
	cin >> vehicleSpeed;
	cout << "Enter speed limit in the zone --->" << setw(8);
	cin >> speedLimit;
}

void processData(double vehicleSpeed, double & ticketAmount, double & speedOver, double speedLimit, double ticketTotal, string plateNumber)
{
	speedOver = vehicleSpeed - speedLimit;

	if (speedOver < 5)

	{
		cout << "No ticket is issued to " << plateNumber << "." << endl;
		ticketAmount = 0.0;
	}
	else if (speedOver <= 20)
	{
		ticketAmount = 150.00 + (5.00 * speedOver);
		ticketTotal = ticketTotal + ticketAmount;
		cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;
	}
	else if (speedOver > 20 && speedOver < 50)
	{
		ticketAmount = 150.00 + (10.00 * speedOver);
		ticketTotal = ticketTotal + ticketAmount;
		cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;

	}
	else if (speedOver >= 50)
	{
		ticketAmount = 1000.00;
		ticketTotal = ticketTotal + ticketAmount;
		cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;
	}
	
	
	
}

void displayResults(double ticketCounter, double totalVehicles, double ticketAmount, double percent, double ticketTotal)
{
	percent = ticketCounter / totalVehicles * 100;
	ticketTotal = ticketTotal / ticketCounter;

	cout << "Tickets were given to " << setprecision(0) << ticketCounter << " out of " << totalVehicles << " total vehicles." << endl;
	cout << "Percent of ticketed vehicles: " << setprecision(2) << percent << "%" << endl;
	cout << "Average ticket amount: " << setprecision(2) << ticketTotal << endl;
}
Topic archived. No new replies allowed.