Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int hours;
- int minutes;
- bool am = true;
- bool pm = false;
- cout<<"Input the hour: "<<endl;
- cin>>hours;
- cout<<"Input the minutes: "<<endl;
- cin>>minutes;
- if(hours > 24 || hours < 1)
- {
- cout<<"Please eneter a number between 1 and 24";
- return 0;
- }
- if(minutes > 60 || hours < 1)
- {
- cout<<"Please eneter a number between 1 and 60";
- return 0;
- }
- if(hours >= 12 && hours <= 24 )
- {
- hours -= 12;
- pm = true;
- am = false;
- }
- else{
- am = true;
- }
- if(pm == true)
- {
- cout<<hours<<":"<<minutes<<" PM"<<endl;
- }
- else if(am == true)
- {
- cout<<hours<<":"<<minutes<<" AM"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement