#include<iostream>
usingnamespace std;
int main()
{
double engine, counter, payment, totalpayment;
char category;
counter=0;
totalpayment=0;
int sentinel='X';
cout<<"Category Year registered Engine capacity (cc) Roadtax "<<endl;
cout<<" A 1995 or earlier 1000 or less 50.00 "<<endl;
cout<<" 1001 - 2000 70.00 "<<endl;
cout<<" More than 2000 90.00 "<<endl;
cout<<" B 1996 or later 1500 or less 150.00 "<<endl;
cout<<" More than 1500 300.00 "<<endl;
do
{
totalpayment=totalpayment+payment;
counter++;
cout<<"\nEnter car category (A|B) or X to stop: ";
cin>>category;
if(category=='A')
{
cout<<"Enter engine capacity of the car: ";
cin>>engine;
if(engine<=1000)
{
payment=50.00;
}
elseif(engine>1000 && engine<=2000)
{
payment=70.00;
}
elseif(engine>2000)
{
payment=90.00;
}
cout<<"\nCar category: "<<category<<endl;
cout<<"Engine capacity of the car: "<<engine<<endl;
cout<<"Amount of the road tax: "<<payment<<endl;
}
elseif(category=='B')
{
cout<<"Enter engine capacity of the car: ";
cin>>engine;
if(engine<=1500)
{
payment=150.00;
}
elseif(engine>1500)
{
payment=300.00;
}
cout<<"\nCar category: "<<category<<endl;
cout<<"Engine capacity of the car: "<<engine<<endl;
cout<<"Amount of the road tax: "<<payment<<endl;
}
else
{
payment=0;
cout<<"Invalid category."<<endl;
}
}while(category!=sentinel);
cout<<"\nTotal number of cars that have been processed: "<<counter-1<<endl;
cout<<"Total of their payments: "<<totalpayment<<endl;
return 0;
}
It doesn't check the category against the sentinel until the loop has finished ... by which time it MUST have output results for either A or B or (the default) else. It is probably easiest to precede your first if in the loop by a check against the sentinel and break out of the loop at that point, rather than checking at the end.
The quickest (but not the best) change would be to change line 70 from else
to elseif ( category!=sentinel )
Since this means the test is written in two places it would be better to have a formulation like
1 2 3 4 5 6 7 8
do
{
// prompt for, and enter, your category
if ( category == sentinel ) break;
// rest of loop
}
BTW, it doesn't make much sense to have category a char and sentinel an int.
Also, you should update totalpayment at the end of the loop, not the start, as payment wouldn't have been set on the first pass.