#include<iostream>
using namespace std;
int main()
{
int hour;
int minutes;
while(1)
{
cout<<"\nEnter an hour in military time between 0 and 23 :
";
cin>>hour;
if(hour>=0 && hour<=23)
{
break;
}
else
{
cout<<"\nInvalid hour\n";
}
}
cout<<"Enter minutes: ";
cin>>minutes;
printf("%d:%02d",hour,(minutes%60));
if(hour>12)
{
hour=hour-12;
printf("\n12-hours format: ");
printf("%d:%02d",hour,(minutes%60));
}
if(hour>=0 && hour<=12)
{
cout<<"\nIt is morning.";
}
else if(hour>=13 && hour<=17)
{
cout<<"\nIt is afternoon.";
}
else if(hour>=18 && hour<=19)
{
cout<<"\nIt is twilight.";
}
else
{
cout<<"\nIt is evening.";
}
return 0;
}
Determine the time period of the day in C++ a. Request an hour in military time...
Can someone solve it with C plz Write a program that inputs a time from the console. The time should be in the format “HH:MM AM” or “HH:MM PM”. Hours may be one or two digits, for example, “1:10 AM” or “11:30 PM”. Your program should include a function that takes a string parameter containing the time. This function should convert the time into a four digit military time based on a 24 hour clock. For example, “1:10 AM” would...
in C++ Write a program that converts a time in 12-hour format to 24-hour format. The program will prompt the user to enter a time in HH:MM:SS AM/PM form. (The time must be entered exactly in this format all on one line.) It will then convert the time to 24 hour form. You may use a string type to read in the entire time at once including the space or you may choose to use separate variables for the hours,...
Time.cpp:
#include "Time.h"
#include <iostream>
using namespace std;
Time::Time(string time)
{
hours = 0;
minutes = 0;
isAfternoon = false;
//check to make sure there are 5 characters
if (//condition to check if length of string is
wrong)
{
cout << "You must enter a
valid military time in the format 00:00" << endl;
}
else
{
//check to make sure the colon is
in the correct...
programming logic C# visual studio Use an if…else-if…else statement to output the following based on an int time entered in military time (ie. 23 == 11:00 p.m., 11 == 11:00 a.m.). You will need to use a ReadLine() and then convert the input to an int value. Based on the input, output the following messages: Input Output 0-11 Good Morning 12-16 Good Afternoon > 16 Good Evening
1. Create a Time class which is designed to contain objects representing times in 12-hour clock format. Eg: 6:58am, 11:13pm, 12:00am (= midnight), 12:00pm (= noon). You can assume the user will enter times in the format given by the previous examples.Provide a default constructor, a set method which is given a String (eg: “9:42am”), a getHours method, a getMinutes method and a boolean isAm method. Also provide a method for returning a string “morning”, “afternoon”, “evening” or “night” appropriate...
How can I modify the program below with this prompt asking "How
many minutes from now do you expect to be home?", and output a
sentence saying "You will get home at HH:MM". ??
It's very URGENT!! Thank you
#include <iostream> #include <ctime> using namespace std; int main) time t t struct tm *now t-time (e) now-localtime(&t); int hour = now->tm.hour; // retrieve current hour int min = now->tm..min; // retrieve current min // get current time // adjust for...
C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion, and two for output (one for 12-hour time and another for 24-hour time). Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing the...
POD 3: Tick Tock Instructions There are 24 hours in a day, but we all think about them differently. Some people and places in the world work with a 24-hour clock that goes from 0:00 to 23:59, while others work with a 12-hour clock that goes from 12.00AM to 11:59PM 24-hour clock 0.00 (midnight) 1200 (noon) 23:59 (one minute before midnight), A COLLAPSE 12-hour clock: *12.00 AM" (midnight) *12:00 PM" (noon) "11:59 PM" (one minute before midnight), You are going...
Write a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock, for example 23:47:55). Here are the input errors (exceptions) that your program should detect and deal with: Receive the input from...
In Python 3, write a function that will take an integer which represents a time given in military time (0 – 2359) and return a string that represents the time in a 12-hour format. If an invalid time is given, the function must return the string “Invalid time”. Examples 1200 will return the string “12:00 PM” 2240 will return the string “10:40 PM” 0600 will return the string “06:00 AM” 2400 will return the string “Invalid time” 1160 will return...