Jun 9, 2012 at 8:28am UTC
Hello cplusplus forum,
can someone point me in the right direction so the vehicle class accepts the options, such as Bus.
When entering a vehicle class, the result is always, Unknown vehicle class!
#include <iostream>
using namespace std;
int main()
{
int vehicleClass;
double toll;
cout << "Enter vehicle class. E.g.: Passenger car. Bus. Truck.: ";
cin >> vehicleClass;
switch (vehicleClass)
{
case 1:
cout << "Passenger car.";
toll = 0.50;
break;
case 2:
cout << "Bus.";
toll = 1.50;
break;
case 3:
cout << "Truck.";
toll = 2.00;
break;
default:
cout << "Unknown vehicle class!";
}
}
// Running doesn't work when you enter a vehicle class.
Jun 9, 2012 at 11:02am UTC
Variable vehicleClass has type int because you defined it as
int vehicleClass;
So it can accept only integer numbers as 1, 2, -10 and so on. You can not enter a string into the variable.
Last edited on Jun 9, 2012 at 11:02am UTC