Help writing a program

As the title says I need help with writing a program that will do the exact following output

Enter hours: 145
Result: Sunday, 1 am
PROGRAM ENDS


the range in ours has to be 0-167...and ofcourse if you inter 0 it will be monday 12 am.... enter 12 for the hours it will display Monday, 12 noon. thank you in advance,
sounds like an homework assignment to me, at least post your effort 1st before you ask for help. So far what have you got
I honestly have nothing at the moment, I have missed a lot of this class because my wife and I just had a child. I do not even know where to begin with this. I don't know if it is just a function, a while loop? array? I've been able to walk myself through the last ones, but the book is of no help on this one.

#include <iostream>
using namespace std;

int main()
{
int input, hours, midnight, noon;

input = 0-167;
hours = input % 24;
midnight = 24;
noon = 12;


// If statement to get correct output.
if (hours == 0 cout << "midnight";)
else if (hours == 12 cout << "noon";)
else if (hours > 0 && hours < 12 cout "a.m.")
else (cout << "p.m.";)

// Get the hours from user.
cout <<"Enter hours:";
cin >> input;

cout <<"Result:" << hours << endl;
cout << "PROGRAM ENDS" << endl;
return 0;
}



getting compile errors... I think my if statement is wrong.
Last edited on
well that doesn't even make sense, cause I still need to get monday through sunday in the result... soooo I need another if statement?
if (hours == 0 cout << "midnight";)

This is just wrong syntax for using an if statement.

1
2
if (hours==0)
{  cout << "midnight";}


http://cplusplus.com/doc/tutorial/control/
ok I see that thank you, next questions... how would I correctly write the

else if (hours>0 && < 12) cout << "a.m.";

is that right?.... and then

else (cout << "p.m.";)

to get the AM PM differnece?

then to get the monday through sunday... would it just be one variable or something like this

const int Monday = 0-23
Tuesday = 24-47
Wednesday = 48-71 ... and so on?




else if (hours>0 && < 12) cout << "a.m.";

This is wrong. I think you meant:

else if (hours>0 && hours< 12) cout << "a.m.";
Now it's just the logic that is wrong; what if the time is 00:13? That should be a.m., right? But your code would give it p.m. Instead, it should be
else if (hours>=0 && hours< 12) cout << "a.m.";

const int Monday = 0-23

This ascribes the value minus 23. I suspect you don't mean that. An int can hold one number. Just one.

Tuesday = 24-47
This gives the variable Tuesday the value minus 23 as well. I think you need to go back and learn before you start using.

http://www.cplusplus.com/doc/tutorial/

I get the feeling that you're not coding in C++, as such, but you're coding in some other language that permits such constructs and trying to force it into C++ syntax. What's your previous programming language experience?
Last edited on
Topic archived. No new replies allowed.