so i was supose to create a software for my class that converts the 24 hour notation to 12, but now i got really lost with it
i used the A symbol to display am and the P symbol to display pm
heres what i have so far but i cant get it to work properlly for each time, here is my code... with a little description of what its supose to do
#include <iostream>
using namespace std;
//Function Declarations
void userInput(int& initHour, int& initMinute);
void convert(int& pHour, int pMinute, char& periodDay);
void output(int pHour, int pMinute, char periodDay);
int main()
{
//Variable declarations
int hour, min; //Used to track the hour and min
char ampm; //Used to track if its am or pm
char redo = 'y';
while (redo == 'y' || redo == 'Y')
{
//Function calls
userInput(hour, min);
convert(hour, min, ampm);
output(hour, min, ampm);
cout << "Would you like to run it again? Y/N: ";
cin >> redo;
}
system("pause");
return 0;
}
void userInput(int& initHour, int& initMinute)
{
cout<< "enter the time seperated by space: ";
cin >> initHour
>> initMinute;
}
void convert(int& pHour, int pMinute, char& periodDay)
{
if(pHour == 24)
{
pHour = 12;
periodDay = 'A';
}
if (pHour == 12)
{
pHour = pHour - 12;
periodDay == 'P';
}
if(pHour > 12 && pMinute >= 0 && pMinute <= 59)
{
pHour = pHour - 12;
periodDay = 'P';
}
if(pHour < 12)
{
periodDay = 'A';
}
}
void output(int pHour, int pMinute, char periodDay)
{
cout << "here is the converted time: " << pHour << " : " << pMinute << periodDay << "\n";
}
thanks for helping