我有一个 C++ 程序,我必须在程序中实现一个 switch 语句。出于某种原因,我不知道 switch 语句没有执行。整个程序如下所示,http ://pastebin.com/VxXFhGkQ 。
我遇到问题的程序部分如下所示,
void processCharges() // function to calculate charges
{
int charges = 0;
// switch statement cannot be applied to strings :(
if(vehicle == "C")
{
cout << "TYPE OF VEHICLE: CAR" << endl;
cout << "TIME IN: " << hh << ":" << mm << endl;
cout << "TIME OUT: " << hhout << ":" << mmout << endl;
cout << "======================================" << endl;
thh = hhout - hh;
tmm = mmout - mm;
int tthh = 0;
if(tmm > 0)
{
tthh = thh + 1;
}
else tthh = thh;
cout << "TOTAL TIME PARKED: " << tthh << endl;
switch(tthh) {
case 1:
if(tthh <= 3) {
charges = 0;
cout << "TOTAL CHARGES:$"<<charges << endl;
break;
}
case 2:
if(tthh >= 4) {
charges = tthh * 1.25;
cout << "TOTAL CHARGES:$"<<charges << endl;
break;
}
}
}
}