Trace the execution of your code.
// here let's say that hours = 23
calculate(hours, minutes);
void calculate(int& h, double& m)
...
if(h>12 && h<=24)
{
h=h-12; // Now hours = 11
m=m-0;
}
}
// hours = 11
display(hours, minutes);
void display(int h, double m)
{
if(h<=12) // this branch is taken sinch h = 11.
{
cout<<"The time in 12 hour format is:"<<h<<":"<<m<<"AM."<<endl;
}
Do you see the problem now?
Ed
void display(int h, double m)
{
if(h<=12)
{
cout<<"The time in 12 hour format is:"<<h<<":"<<m<<"AM."<<endl;
}
if(h>12 && h<=24)
{
cout<<"The time in 12 hour format is:"<<h<<":"<<m<<"PM."<<endl;
}
}