/*
File name : looping
Author : Muhammad Bin Md Yazed
Date created : 26/10/2012
Objective(s) : 1) using selection
2) to make parking ticket machine
*/
#include <iostream>
usingnamespace std;
int main()
{
char vehicleType;
char plateNumber [8];
float totalHour, fees;
cout<< " ##### WELCOME TO THE AUTO PAY MACHINE #####"<<endl
<<endl <<endl;
cout<< " A for Motorcycle."<<endl;
cout<< " B for Car."<<endl;
cout<< " C for Lorry."<<endl <<endl;
cout<< " Please enter your vehicle class : ";
cin>> vehicleType;
cout<< "\n\n Please enter your plate number : ";
cin>> plateNumber;
cout<< "\n\n Please enter Total Hours : ";
cin>>totalHour;
cout<<endl <<endl;
switch (toupper(vehicleType))
{
case'A' :
if (totalHour == 2)
{
fees=0.50;
}
elseif ((totalHour > 2) && (totalHour <= 6))
{
fees=(totalHour-2)*0.50+0.50;
}
elseif ((totalHour > 6) && (totalHour <= 12))
{
fees=(totalHour-6)*1.00+1.50;
}
else
{
fees=20; //+7.50
}
break;
case'B' :
if (totalHour == 2)
{
fees=1.00;
}
elseif ((totalHour > 2) && (totalHour <= 6))
{
fees=(totalHour-2)*1.00+1.00;
}
elseif ((totalHour > 6) && (totalHour <= 12))
{
fees=(totalHour-6)*1.50+5.00;
}
else
{
fees=50; //+14.00
}
break;
case'C' :
if (totalHour == 2)
{
fees=1.50;
}
elseif ((totalHour > 2) && (totalHour <= 6))
{
fees=(totalHour-2)*2.00+1.50;
}
elseif ((totalHour > 6) && (totalHour <= 12))
{
fees=(totalHour-6)*2.50+9.50;
}
else
{
fees=100; //+34.50
}
break;
default :
cout<<"\a\a\a Your enter wrong vehicle class."
<<" Please re-enter your vehicle class."<<endl <<endl;
}
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout<<" "<<"Plate Number : "<<plateNumber
<<" Vehicle Class : "<<vehicleType<<" Your fees"
<<" is : RM " <<fees <<endl <<endl;
system ("PAUSE");
return 0;
}
and the output as follow :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
##### WELCOME TO THE AUTO PAY MACHINE #####
A for Motorcycle.
B for Car.
C for Lorry.
Please enter your vehicle class : a
Please enter your plate number : csba4r
Please enter Total Hours : 7
Plate Number : csba4r Vehicle Class : a Your fees is : RM 2.50
Press any key to continue . . .
my question are :
-how to convert user lower case input vehicleType and plateNumber to upper case?
-why when user enter invalid Vehicle class, no output from default?