Homework Help Question & Answers

# How can I modify the program below with this prompt asking "How many minutes from now...

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 today's sunset time (16-21): " << endl; cin >> hour; cout <<" Enter the minutes part of today's 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

#### Homework Answers

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.

Know the answer?
Your Answer:

#### Post as a guest

Your Name:

What's your source?

#### Earn Coin

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" <<...

• ### Need C++ help for minor issue Will rate High!

Please figure out how to make program output the name and total time an employee spends on the job.Here is code I have for now:I've updated the code with the missing portion#include<iostream>#include<string>using namespace std;void timeOnJob( int arvHr, int arvMin, bool arvIsAm, int depHr, int depMin, bool depIsAm);int main(){string employeeName;int arrivalHr;int arrivalMin;bool arrivalAM;int departureHr;int departureMin;bool departureAM;char response;char discard;char isAM;cout << "This program calculates the total time spent by an "<<"employee on the job."<< endl;cout << "To run the program, enter (y/Y):...

• ### Need help with C++ program // find() function sample input: hello there world sample output: if f...

need help with C++ program // find() function sample input: hello there world sample output: if f is entered(which accesses the find function), user enters a letter they would like to find how many times it occurred in the string, for example: e. and it should outputs: 3 occurrences #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512 struct node { char c; struct node *next; }; node *str = NULL; node *addOnto(struct node *list, char *a)...

• ### 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...

• ### 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...

• ### 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...

• ### 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...

• ### 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...

• ### I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols [email protected],#,\$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

• ### fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...