#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
//int x = 5;
//cout << setw(2) << setfill('0') << x;
int hours, mins,secs;
cout<<"Enter a time value in the following format: HH MM SS\n";
cin>>hours>>mins>>secs;
if(hours>24)
{
cout<<"Hour must be between 0 and 23 inclusive.";
}
switch(hours)
{
case 00:
cout<<"12:"<<mins<<":"<<secs<<"AM\n";
break;
case 01:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 02:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 03:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 04:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 05:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 06:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 07:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 08:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 09:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 10:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 11:
cout<<hours<<":"<<mins<<":"<<secs<<"AM\n";
break;
case 12:
cout<<hours<<":"<<mins<<":"<<secs<<"PM\n";
break;
case 13:
cout<<"01:"<<mins<<":"<<secs<<"PM\n";
break;
case 14:
cout<<"02:"<<mins<<":"<<secs<<"PM\n";
break;
case 15:
cout<<"03:"<<mins<<":"<<secs<<"PM\n";
break;
case 16:
cout<<"04:"<<mins<<":"<<secs<<"PM\n";
break;
case 17:
cout<<"05:"<<mins<<":"<<secs<<"PM\n";
break;
case 18:
cout<<"06:"<<mins<<":"<<secs<<"PM\n";
break;
case 19:
cout<<"07:"<<mins<<":"<<secs<<"PM\n";
break;
case 20:
cout<<"08:"<<mins<<":"<<secs<<"PM\n";
break;
case 21:
cout<<"09:"<<mins<<":"<<secs<<"PM\n";
break;
case 22:
cout<<"10:"<<mins<<":"<<secs<<"PM\n";
break;
case 23:
cout<<"11:"<<mins<<":"<<secs<<"PM\n";
break;
}
}
Yes, you might have to come with another way of dealing with the input.
The easiest way would be to have the input as ordinary int without the leading zero, then do math on that number.
If the leading zero has to be there, then make the variable a string, determine whether the zero is there and remove it, then convert the rest to a number.