#include <iostream>
#include <string>
using namespace std;
int main()
{
    int hour;
    cout << "Enter an integer for hour and a suffix (am/pm): ";
    cin >> hour;
    if (cin.fail())
    {
        cout << "Error: Not an integer." << endl;
    }
    else if (hour < 1 || hour > 12)
    {
        cout << "Error: The hour must be between 1 and 12." << endl;
    }
    else
    {
        string suffix;
        cin >> suffix;
        cout << hour << suffix ;
        if (suffix == "am" || suffix == "pm")
        {
            if (hour == 12) 
            {
                hour = 0;
            }
            if (suffix == "pm")
            {
                hour = hour + 12;
            }    
            cout << "\n" << hour << endl;
        }
        else
        {
            cout << "Error: The suffix must be am or pm." << endl;
        }
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: