Hi all.
I am having trouble with my code. I have played around with it for a while, and I just can't seem to get it. The only thing I am having trouble with is it getting to output the a.m. and the p.m. correctly. it always outputs p.m. no matter what the input is
I am a student, and I am learning. The chapter this week is using value vs reference parameters.
#include<iostream>
#include<iomanip>
using namespace std;
//function prototypes
void getInput(int& hour, char& ch, int& minutes);
void convertTo12(int& hour);
void printOutput(int& hour, char ch, int minutes, char& day);
//begin main
int main()
{
int hour;
char ch;
int minutes;
char day;
getInput(hour, ch, minutes);
convertTo12(hour);
printOutput(hour, ch, minutes, day);
system("pause");
return 0;
}//end main
//beging getinput. Get's the input from the user.
void getInput(int& hour, char& ch, int& minutes)
{
cout << "Please enter the time in 24 hour format." << endl;
cin >> hour >> ch >> minutes;
}// end getIntput
//begin converTo12. Converts the input to 12 hour format and
// outputs a or p depending whether it is a.m. or p.m. this
// function does not output the am or pm to the screen.
void convertTo12(int& hour)
{
char day;
if (hour >= 12)
day = 'p';
else
day = 'a';
if(hour >= 13)
{
hour = hour - 12;
}
}//end Converto12
// begin printOutput. Prints the output to the screen
void printOutput(int& hour, char ch, int minutes, char& day)
{
cout << hour << ch << minutes;
if (day = 'p')
cout << "p.m.";
else
cout << "a.m.";
}//end printOutput