help with a time and date program

Hi-
I am really needing some help writing the following program;

DIRECTIONS: Write a C++ program which will prompt the user for an int representing hours. This value will be in the range 0 - 167 inclusive. Your program should then display a day and time(hours only) followed by am, pm, midnight, or noon. Assume time begins at midnight 12am Monday. Finally, your program will output 'PROGRAM ENDS' (the single quotes are not displayed), followed by a single newline. Then, your program terminates.

Here are some examples:

Enter hours:13
Result: Monday, 1 pm
PROGRAM ENDS

Enter hours:25
Result: Tuesday, 1 am
PROGRAM ENDS

Any help is greatly appreciated. Thanks
You're most likely not getting any form of complete code, so it would be best if you showed what you have right now and explain where you are stuck or need help. Only then you'll get decent answers because I doubt anyone here will do the homework for you.

Basically, if we see effort from you, we might put some effort ourselves.
Sorry bout that...was in a rush and forgot to paste it. Hear is what I have so far. I have been working on it for a while now and am just stuck. Thanks..


13 #include <iostream>
14 using namespace std;
15
16 int main()
17 {
18 hnumber = input % 24
19 if hnumber == 0 cout midnight
20 else if hnumber == 12 cout noon
21 else if hnumber > 0 && number < 12 cout "a.m."
22 else cout "p.m."
23
24 cout <<"Enter hours:"
25 cin >>hnumber;
26
27 cout <<"Result:"
28 cin >>
29
30 cout <<"Program Ends"<< endl;
31 }
The variable "input" is not declared.
The variable "hnumber" is not declared.
The variable "midnight" is not declared.
The variable "noon" is not declared.
The if() statement in line "19" doesn't have the required parenthesis. Same goes for the else if()'s that follow.
Line "24" is going after the calculations, which makes no sense. You must collect input first, then calculate.
Line "28" has the standard input plus the extraction operator, but no right-hand side operand, plus it doesn't have the required ending semi-colon.

So at this point the best help I can give you is a basic C++ tutorial because you don't yet master the basics of the language, meaning that at this point you are unable to fulfill the homework's requirement. Read the tutorial first, then try to solve the homework.

If you get questions about the basics of C++, then post here the specific questions.

http://www.cplusplus.com/doc/tutorial/
This getting any closer? I know it's sad, but i have not missed a class and am still this lost. Any tips would be awesome...Thanks


13 #include <iostream>
14 using namespace std;
15
16 int main()
17 {
18 int input, hnumber, midnight, noon
19
20 input = 0-167
21 hnumber = input % 24
22 midnight = 24
23 noon = 12
24
25 if (hnumber == 0 cout midnight)
26 else if ( hnumber == 12 cout noonn
27 else if( hnumber > 0 && number < 12 cout "a.m.")
28 else( cout "p.m.")
29
30 cout <<"Enter hours:";
31 cin >>hnumber;
32
33 cout <<"Result:";
34 cin >> i have no idea what goes here!
35
36 cout <<"Program Ends"<< endl;
37
38 }
Just a tini tiny better. You have declared variables input, hnumber, midnight and noo, but you continue to miss every required semi-colon. Tip: Don't post without compiling. Don't have a compiler at hand? Use one online. Try www.ideone.com. You can compile C++ code there (and many other languages for that matter).

Don't post any more code with "is this better?". Instead, try it yourself in a compiler. And also don't continue posting questions without reading the tutorial. You are missing a lot of the basics, and you have no regard as to where you close your parenthesis.

In short: Read the entire C++ tutorial, then do some Hello World exercises, then do some more exercises, then try to solve this homework.
Topic archived. No new replies allowed.