hi guys,

Below is my program and it is giving me turf time.I want it to read-in 1-for counting cars,2-for counting money and Esc-key for displaying totals.Pliz give me ideas.(i'm using Microsoft-visual c++)

#include <iostream>
using namespace std;
#include <conio.h>


class tollBooth
{
  private:
    unsigned int cars;
    double money;
  public:
    tollBooth() : cars(0), money(0)
      {     }
    void payingCar();
    void nopayCar();
    void display() const;
    
};

void tollBooth::payingCar()
{
  cars++;
  money+=0.5;
}

void tollBooth::nopayCar()
{
  cars++;
}

void tollBooth::display() const
{
  cout << "Total cars = " << cars <<"\n\n"<< " Total money = " << money;
}

int main()
{
  tollBooth R;

 
  char chrt= ' ';

  cout << "Press '1' for paying cars and '2' for non-paying cars : " <<
endl;

  cin>>chrt;
  
  while (chrt !='3')
  {
    
	chrt = getch();
    switch (chrt)

    {
      case '1':
		  
		  R.payingCar();

		  break;

      case '2':
		  ++money;

		  R.nopayCar();

		  break;

	  default:
		  cout<<"should not be here : ";
		  cin>>chrt;
    }

  }
  R.display();
    

  return 0;
}

>Pliz give me ideas.
Ideas for what? What are you trying to do that you need help with? I'll assume that because '3' is not the scan code for Esc, you don't know what to test for. Try 27, if I remember correctly, that's Esc. If you search the boards for threads talking about using the arrow keys, you'll see some of my code for properly reading a scan code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.