Debugglng Informatlon for Loco overTime O DESCRIPTION Value too high DEBUG INFO Your instructor has chosen to give you the following information to help you debug your code and improve your submission. COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 1 Loco 2 5900 YOUR CODE'S OUTPUT 1 what is your name? What time is it? (0-2400)What are you doing up, Loco 2 THE CORRECT OUTPUT OF THE TEST CASE 1 What is your name? What time is it? (0-2400)That is an illegal time, Loco 2 "UNIX DIFF OF CORRECT OUTPUT AND YOUR OUTPUT 1c1 < what is your name? What time is it? (0-2400)What are you doing up, Loco > what is your name? What time is it? (0-2400)That is an illegal time, Loco PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are mlssing, red indicates things in your output that shouldn't be there. The - character refers to newlines, so the green - character refers a newline you are missing in your output and the red refers to a newiline you need to remove from your output. 1 what is your name? What time is it? (0-2400)WThat areis youan doinllegal uptime, Locod Debugglng Informatlon for Loca crazytlme O DEBUG INFO Your instructor has chosen to give you the following information to help you debug your code and improve your submission. COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 1 Loca 2 -1200 YOUR CODE'S OUTPUT 1 what is your name? What time is it? (0-2400)What are you doing up, Loca 2 THE CORRECT OUTPUT OF THE TEST CASE 1 what is your name? What time is it? (0-2400)That is an illegal time, Loca 2 "UNIX DIFF OF CORRECT OUTPUT AND YOUR OUTPUT 1c1 < what is your name? What time is it? (0-2400)What are you doing up, Loca > what is your name? What time is it? (0-2400)That is an illegal time, Loca PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are mlssing, red indicates things in your output that shouldn't be there. The a character refers to newlines, so the green character refers a newline you are missing in your output and the red refers to a newiline you need to remove from your output. 1 what is your name? What time is it? (0-2400)WThat areis youan doinllegal uptime, Locad TIT
I am having some issues with my code when I run it.
The instruction for the hw was as follows:
For this C++ hw
Create a function called time2Greeting.
It takes a time (in military time) and returns a string with the right greeting.
Good Morning 4AM to before noon.
Good Afternoon Noon to before 5PM
Good Evening from 5PM to 11PM
What are you doing up at this hour? between 11 and 4AM
For illegal values, say:
That is not a valid time.
Example:
What is your name? John
What time is it? 1315
Good afternoon, John.
My code:
#include <iostream>
#include <string>
using namespace std;
//method to compute the greeting at a certain time
string time2greeting(int time)
{
//create a string to hold greatings
string greeting;
//if time is between 11PM and 4AM
if (time > 2259 || time < 400)
//set the greating " What are you doing up,"
greeting = "What are you doing up, ";
//if time is between from 5PM to 11PM
else if (time > 1659)
//set the greeting "good evening"
greeting = "Good Evening, ";
//if time is from Noon to before 5PM
else if (time > 1159)
//set the greeting "good Afternoon"
greeting = "Good Afternoon, ";
//if time is greater tha 359
else if (time > 359)
//set the greeting "good Morning"
greeting = "Good Morning, ";
//For illegal values, say:
else
//set the greeting
greeting = "That is an illegal time, ";
//return the greeting
return greeting;
}
//define main method
int main()
{
//declare the variables
string name, greeting;
int time;
//prompt the user to enter the name
cout << "What is your name? ";
//scan for the value
cin >> name;
//prompt the user to enter the time
cout << "What time is it? (0-2400)";
//scan for the time
cin >> time;
// call and print time2greeting
greeting = time2greeting(time);
//print the output
cout << greeting << " " << name << endl;
//return
return(0);
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images