Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program which will prompt the user for an int representing hours. Th

ID: 3632642 • Letter: W

Question

Write a C++ program which will prompt the user for an int representing hours. This value will be in the range 0 - 167 inclusive. Your program should then display a day and time (hours only) followed by am, pm, midnight, or noon. Assume time begins at midnight 12am Monday. Finally, your program will output 'PROGRAM ENDS' (the single quotes are not displayed), followed by a single newline. Then, your program terminates.

1) declare all variables as ints.
2) ensure that there is exactly one newline after the result line and exactly one newline after 'PROGRAM ENDS'.

ASSUMPTIONS:
1) You may assume that time entered is an int in range 0 - 167
inclusive.

Explanation / Answer

please rate - thanks

please message me any problems to fix before rating - thanks again

#include <iostream>
#include <string>
using namespace std;
int main()
{int hours, day,ap;
cout<<"Enter hour between 0 and 167: ";
cin>>hours;
cout<<"hours is ";
day=hours/24;
hours=hours%24;
if(day==0)
    cout<<"Monday ";
else if(day==1)
    cout<<"Tuesday ";
else if(day==2)
    cout<<"Wednesday ";
else if(day==3)
    cout<<"Thursday ";
else if(day==4)
    cout<<"Friday ";
else if(day==5)
    cout<<"Saturday ";
else
    cout<<"Sunday ";
if(hours>=12)
    {ap=1;
     if(hours>=13)
         hours-=12;
    }
else
    ap=0;
    if(hours==0)
         cout<<"12";
    else
         cout<<hours;
if(ap==0 )
    if(hours==0)
         cout<<"midnight ";
    else
         cout<<"am ";
else
    if(hours==12)
         cout<<"noon ";
    else
         cout<<"pm ";
cout<<"PROGRAM ENDS ";
system("pause");
return 0;
}


   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote