Okay I am writing a program that is called tollbooth and I had to add a second tollbooth to it. But why does my code not work?
Code:
// ex6_2.cpp
// uses class to model toll booth
#include <iostream>
using namespace std;
#include <conio.h>
const char ESC = 27; //escape key ASCII code
const double TOLL = 0.5; //toll is 50 cents
////////////////////////////////////////////////////////////////
class tollBooth
{
private:
unsigned int totalCars; //total cars passed today
double totalCash; //total money collected today
public: //constructor
tollBooth() : totalCars(0), totalCash(0.0)
{ }
void payingCar() //a car paid
{ totalCars++; totalCash += TOLL; }
void nopayCar() //a car didn't pay
{ totalCars++; }
void display() const //display totals
{ cout << "\nCars=" << totalCars
<< ", cash=" << totalCash
<< endl; }
};
//---------------------------------------------------------------------
class tollBooth2
{
private:
unsigned int totalCars; //total cars passed today
double totalCash; //total money collected today
public: //constructor
tollBooth() : totalCars(0), totalCash(0.0)
{ }
void payingCar() //a car paid
{ totalCars++; totalCash += TOLL; }
void nopayCar() //a car didn't pay
{ totalCars++; }
void display() const //display totals
{ cout << "\nCars=" << totalCars
<< ", cash=" << totalCash
<< endl; }
};
//---------------------------------------------------------------------
int main()
{
tollBooth booth1, booth2; //create a toll booth
char ch;
cout << "\nPress 0 for each non-paying car,"
<< "\n 1 for each paying car,"
<< "\n 2 to go to second tool booth,"
<< "\n Esc to exit the program.\n";
do {
ch = getche(); //get character
if( ch == '0' ) //if it's 0, car didn't pay
booth1.nopayCar();
if( ch == '2' )
goto tollBooth2;
if( ch == '1' ) //if it's 1, car paid
booth1.payingCar();
} while( ch != ESC ); //exit loop on Esc key
booth1.display(); //display totals
getch();
return 0;
}
Here are the errors:
[C++ Warning] Ex6_2.cpp(4): W8058 Cannot create pre-compiled header: write failed
[C++ Error] Ex6_2.cpp(34): E2040 Declaration terminated incorrectly
[C++ Error] Ex6_2.cpp(44): E2040 Declaration terminated incorrectly
[C++ Error] Ex6_2.cpp(44): E2190 Unexpected }
[C++ Error] Ex6_2.cpp(44): E2190 Unexpected }
[C++ Error] Ex6_2.cpp(68): E2448 Undefined label 'tollBooth2'
What do I do?
Code Tags changed from [ Quote ] tags by Kermi3....good effort .