military time converter using functions
hello
i am making a program where the user enters the hours and minutes in military time(24hrs) and the program will output the time in regular time(12hrs). i need to use funtions, one for the input, one for the coverting, and one for the output. im new to funtions and cant seem to get it to work. i can input the time fine but the program will not convert or output the right time. it keeps saying the variable afternoon is being used without being initialized, and then it outputs the same time that i input. can i get some hints on what may be wrong or something.
thanks
Code:
#include<iostream>
using namespace std;
void military(int& mhour,int& mmin);
void convert(int mhour, int& hours, char afternoon);
void print(int hours,int mmin,char afternoon);
int main()
{
int mhour,mmin,hours;
char afternoon;
military(mhour,mmin);
convert(mhour,hours,afternoon);
print(hours,mmin,afternoon);
system("pause");
return 0;
}
void military(int& mhour,int& mmin)
{
cout<<"enter the hours in 24 hour format<0-24>\n";
cin>>mhour;
cout<<"enter the minutes in 24 hour forman<00-59>\n";
cin>>mmin;
}
void print(int hours, int mmin,char afternoon)
{
cout<<"The time in 12 hour format is "<<hours<<":"<<mmin<<" "<<afternoon<<"m \n";
}
void convert(int mhour, int& hours, char afternoon)
{
if(mhour>12)
{
hours=mhour;
afternoon='A';
}
if(mhour<=13)
{
hours=mhour-12;
afternoon='P';
}
}