输入车辆类会出错

时间:2012-06-09 08:30:10

标签: c++ switch-statement

有人能指出我正确的方向,所以车辆类接受选项,例如巴士。 进入车辆​​类时,结果总是,未知的车辆类!

#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.

0 个答案:

没有答案