Access Millions of academic & study documents

Assessment 7

Content type
User Generated
Showing Page:
1/2
ASSESSMENT
Create a program that will ask the user to input time in a 24-hour notation
and output it in 12-hour notation. For example, if the input is 13:45, the
output should be 1:45. The program should instruct the user to always
enter exactly 5 characters. So for example, nine o‘clock should output
09:00.
FILENAME: PTASK.cpp
Note: Please copy the correct program on the space provided.
#include<iostream>
using namespace std;
int main(){
int twenty_four_hrs;
cout<<"Enter the time in twenty four hour format:";
cin>>twenty_four_hrs;
cout<<"\n";
int hrs,min;
hrs=twenty_four_hrs/100;
min=twenty_four_hrs%100;
cout<<"Time in Twelve Hour Format is:\t";
if(hrs==0&&hrs!=12){
hrs=12;
printf("%.2d:%.2d AM\n",hrs,min);
}
else if(hrs==12&&hrs!=0){
hrs=12;
printf("%.2d:%.2d PM\n",hrs,min);
}
else if(hrs<12&&hrs!=0){
hrs=hrs;
min=min;
printf("%.2d:%.2d AM\n",hrs,min);
}
else if(hrs>12&&hrs!=0)
{
hrs=hrs-12;
min=min;
printf("%.2d:%.2d PM\n",hrs,min);
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
ASSESSMENT Create a program that will ask the user to input time in a 24-hour notation and output it in 12-hour notation. For example, if the input is 13:45, the output should be 1:45. The program should instruct the user to always enter exactly 5 characters. So for example, nine o‘clock should output 09:00. FILENAME: PTASK.cpp Note: Please copy the correct program on the space provided. #include using namespace std; int main(){ int twenty_four_hrs; couttwenty_four_hrs; cout ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4