This is the question:
Write a program that converts from 24hour notation to 12hour notation.For example, it should
convert 14:30 to 2:30 PM. The input is given as two integers. Verifies that a legitimate 24hour
notation has been input by using the assert statement
Please tell me if my code is correct
Here's my code:
#include <iostream>
#include <cassert>
using namespace std;
int main()
{
int hours, mins;
string period;
cout << "Enter the hours you wish to convert(0 - 2)";
cin >> hours;
assert(hours >= 0 && hours <= 24);
cout << "Enter the minutes you wish to convert(0 - 59);
cin >> mins;
assert(mins >= 0 && mins <= 59);
if(hours > 12)
{
hours = hours - 12;
period = "PM";
}
else
{
period = "AM";
}
cout << "The converted time in 12-hour notation is " <<
hours << ":" << mins << period;
return 0;
}