the previous given input in console.
how to can we get input in new lines without overwriting the previous one ?
// Program to make a tollBooth class
const char ESC=27;
const double toll= 0.5;
class tollBooth{
unsigned int total_cars;
double money;
public:
tollBooth():total_cars(0),money(0){}
void pay_cars(){
total_cars++;
money+=toll;
}
void non_pay_cars(){
total_cars++;
}
void display(){
cout<<"Number of paying cars: "<<total_cars<<endl
<<"Number of amount collected: "<<money<<" cents"<<endl;
}
};
int main(){
tollBooth booth1;
char ch;
cout<<"\nPress 0 for paying car\nPress 1 for non paying cars\nPress ESC to exit program"<<endl;
do{
ch = getche();
if(ch=='0'){
booth1.pay_cars();
}
if(ch=='1'){
booth1.non_pay_cars();
}
}while(ch!=ESC);
booth1.display();
return 0;
}
Don't use functions from the conio header.
Обсуждают сегодня