1. Your use of 'days' in line 45 is fine - you just aren't setting the value of 'days' anywhere (like in line 30, instead of outputting it at that point)
2. You're setting 'hnumber' from 'input' (line 22, which is correct math, BTW) before you've got the value of 'input' from the user at line 27. Move hnumber's assignment after that point.
Not quite yet. I really appreciate your tips but i still can't get it to compile. If you got a sec could you please take a look at the changes. Thanks!
16 int main()
17 {
18 int input, hnumber, midnight, noon;
19 int days;
20
21 input = 0-167;
22
23 cout<<"Enter hours:";
24 cin>> input;
25
26 if (input <= 23) days ="Monday\n";
27 else if (input <= 47) days ="Tuesday\n";
28 else if (input <= 71) days ="Wednesday\n";
29 else if (input <= 95) days ="Thursday\n";
30 else if (input <= 119) days = "Friday\n";
31 else if (input <= 143) days ="Saturday\n";
32 else if (input <= 167) days ="Sunday\n";
33
34 hnumber = input % 24;
35 midnight = 24;
36 noon = 12;
37
38 if (hnumber == 0) cout<<"midnight\n";
39 else if (hnumber == 12) cout<<"noon\n";
40 else if (hnumber >= 0 && hnumber <= 12) cout<<"am\n";
41 else if (hnumber >= 12 && hnumber <= 12)
42 cout<<"pm\n";
43
44
45 cout<< "Result:" << days << " ," << hnumber << endl;
46
47 cout<< "Program Ends"<< endl;
48 }
At a quick look I think this would compile fine, what error are you getting?
The only problem I can spot is on line 41 elseif (hnumber >= 12 && hnumber <= 12)
which is the same as elseif (hnumber == 12)
maybe it should be <=24 for line 41?
Thanks for getting back to me..here is the error message i am receiving:
jhprogram3closer.cpp:25: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:26: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:27: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:28: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:29: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:30: error: invalid conversion from `const char*' to `int'
jhprogram3closer.cpp:31: error: invalid conversion from `const char*' to `int'
Not quite, no - your original code had 'days' defined as string days;, which you've changed to an int. If you change it back to be a string, things should be fine ...
1 2 3 4 5 6 7
string days;
...
if (input <= 23) days = "Monday\n";
...