My program outputs:
Enter hours:16
Result: Monday, 16 pm
PROGRAM ENDS
It is supposed to output:
Enter hours:16
Result: Monday, 4 pm
PROGRAM ENDS
Here is my program. Is there a problem with my time formula? Thanks!
int main()
{
int input, time;
cout<<"Enter hours:";
cin>> input;
if (input <= 23) cout<< "Result: Monday, ";
else if (input <= 47) cout<< "Result: Tuesday, ";
else if (input <= 71) cout<<"Result: Wednesday, ";
else if (input <= 95) cout<<"Result: Thursday, ";
else if (input <= 119) cout<< "Result: Friday, ";
else if (input <= 143)cout<<"Result: Saturday, ";
else if (input <= 167)cout<<"Result: Sunday, ";
time = input % 24;
if (time == 0) cout<<"12 midnight\n";
else if (time == 12) cout<<"12 noon\n";
else if (time > 0 && time < 12) cout<< time<<" am\n";
else if (time > 12)cout<< time<<" pm\n";
cout<< "PROGRAM ENDS"<< endl;
}
Where does your code take the input value 16 and turn it into a 4?
else if (time > 12)cout<< time<<" pm\n";
should be
else if (time > 12)cout<< time-12<<" pm\n";
That did it...thank you soo much!