A function that increments

How would I write a function that increments something like a total of cars and the adds 2.00 to a cash total.

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
#include <iostream>
#include<iomanip>
using namespace std;

class tollbooth
{
private:
		int totalcars;
		double amount;

public:
	tollbooth();
	void payingCar(int,double);
	void nonpayCar(int);
	void display();

};

tollbooth::tollbooth()
{
	tollbooth.totalcars=0;
	tollbooth.amount=0.0;

}

void tollbooth::payingCar(int car, double amt)
{
	 for( int a = 0; a >0; a = a + 1 )
	 {
		 car=a;
         amt=a*car;

	 }


	 return car, amt;


}
in your constructor you don't need the . operator, you can simply do "totalcars=0" and "amount=0.0". and in your paying car function your loop makes no sense. You are initializing a to zero and the terminator is when a is greater than 0, this doesn't make sense. Also, the 3rd part of the for loop should be a++ not a+1. What exactly do you want the payingcar function to do?

Also, void functions don't return anything, so the return statement won't work.
Last edited on
Im trying to increment a car/truck total and 2.00 dollars to cash total.
I need to keep track how many cars pass by a tollbooth and add 2.00 dollars for each car that pass by the tollbooth
your payingCar function could do something like, amount+=2.00 and totalcars++ for every time you are passing a vehicle to the function.
Last edited on
Topic archived. No new replies allowed.