Question

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 local timezone cout << Enter the hours part of todays sunset time (16-21): << endl; cin >> hour; cout << Enter the minutes part of todays sunset time (0-59) << endl; cin > min hour < 12) cout << Good Morning Xiayoe else ifhour > 12 && hour <14) cout << Good afternoon Xiayoe else cout << Good evening Xiayoe return 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

#include <iostream>
#include <ctime>

using namespace std;

int main(){
time_t t;
struct tm *now;
t=time(0); //get current time
now=localtime(&t); //adjust for local time zone
int hour= now->tm_hour; //retrieve current hour
int min = now->tm_min; // retrieve current min
int c_min; // To read the number of minutes from user


cout << "How many minutes from now do you expect to be home?" << endl;
cin >> c_min;

// If number of minutes user entered and current number of minutes from current time sum <= 59
if ( c_min + min <= 59){
cout << " You will get home at " << hour << ":" << c_min+min << endl;
}

else if ( c_min + min > 59)
{
int e_min=0;
int e_hr=0;
e_min= (c_min+min)%60;
e_hr = (c_min_min)/60;
cout << " You will get home at " << hour+e_hr << ":" << e_min << endl;
}

/*if ( hour < 12 ) {
cout << " Good Morning Xiayoe";
}
else if ( hour > 12 && hour < 14){
cour << " Good afternoon Xiayoe";
}
else{
cout << " Good evening Xiayoe";
}*/

return 0;
}

Note: I have commented output statements of good morning, good afternoon and good evening as they are not needed.

Add a comment
Know the answer?
Add Answer to:
How can I modify the program below with this prompt asking "How many minutes from now...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h>...

    I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h> #include <windows.h> using namespace std; int main() { int m, s,h; cout << "A COUNTDOWN TIMER " << endl; cout << "enter time in hours here" << endl; cin >> h; cout << "enter time in minutes here " << endl; cin >> m; cout << "enter time in seconds here" << endl; cin >> s; cout << "Press any key to start" <<...

  • I created a struct for Car and now I need to turn it into a class...

    I created a struct for Car and now I need to turn it into a class for Car. Below is the code that I wrote for the structure. For the class, we are suppose to make the data in the class Car private, revise the input so the input function will only read the data from the user, and then it will call an additional function named setUpCar which will put the data into the object. Not sure how to...

  • C++. here is the problem that kind of the same with the example that i did...

    C++. here is the problem that kind of the same with the example that i did in class (attach picture). however, this require use the loop to do, I get confuse. pls help me! thank you! Problem: Define a class to implement the time of day in a program. To represent time, use three member variables: one to represent the hours, one to represent the minutes, and one to represent the seconds. Also define the following member functions in the...

  • Create a new file (in Dev C++) Modify program above to use a vector instead of...

    Create a new file (in Dev C++) Modify program above to use a vector instead of an array. Header comments must be present Prototypes must be present if functions are used Hello and goodbye messages must be shown Vector(s) must be used for implementation Use comments and good style practices ====================================================================================================== #include <iostream> using namespace std; int main() { cout<<"Welcome! This program will find the minimum and maximum numbers in an array."<<endl; cout<<"You will be asked to enter a number...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • How can I modify my program to return the option with the highest amount ? //A...

    How can I modify my program to return the option with the highest amount ? //A new author is in the process of negotiating a contract for a new romance novel. //The publisher is offering three options. //1. The author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. //2. In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold....

  • I need to modify my C++ code so it can get the min value of the...

    I need to modify my C++ code so it can get the min value of the stack code is as follows: #include <iostream> using namespace std; #define MAX_SIZE 100 class Stack { private: int S[MAX_SIZE]; int top; public: Stack() {   top = -1; } void push(int x) {   if (top == MAX_SIZE - 1) {    cout << "Stack is Full." << endl;    return;   }   S[++top] = x; } void pop() {   if (top == -1) {    cout << "Stack is...

  • My if/else statement wont run the program that I am calling. The menu prints but once...

    My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm? #include <iostream> #include "miltime.h" #include "time.h" #include "productionworker.h" #include "employee.h" #include "numdays.h" #include "circle.h" using namespace std; int main() { int select=1;     while (select>0) { cout << "Option 1:Circle Class\n"<< endl; cout << "Option 2:NumDay Class\n" << endl; cout <<"Option 3:Employee and Production...

  • please do the program in simple programming it is for my first c++ computer class i...

    please do the program in simple programming it is for my first c++ computer class i posted the example on pic 2,3 which is how this should be done Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT