Urgent! Help with days of the week array

Declare an array of floating point elements called week that can be referenced by using any day of the week as a subscript assume sunday is the first.
Okay. Just need a heads up here. I assume this means I am supposed to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream> 
using namespace std;

int main()
{

enum DayOfWeek { Su, Mo, Tu, We, Th, Fr, Sa };
const int N = Sa + 1;

week[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; // error week is undefined

DayOfWeek currentDay; // what does this do? Does it plug current day into dayofweek?



switch ( currentDay )
{
case Su:
   week[Su] = 0.0;
   break;
case Mo:
   week[Mo] = 1.0;
    break;
case Tu:
   week[Tu] = 2.0;
    break;
case We:
   week[We] = 3.0;
    break;
case Th:
   week[Th] = 4.0;
    break;
case Fr:
   week[Fr] = 5.0;
    break;
case Sa:
   week[Sa] = 6.0;
    break;
default:
   std::cout << "Invalid day of week\n";
   break;
}
}


Ok so does that look right? I have a few questions in the comments. How do you defind week[N]. Also What does DayofWeek current day do?
Thanks.
How do you defind week[N]


Depends what it's meant to be an array of. Here are some examples:

1
2
double week[N]; // an array of N double values
int week[N]; // an array of N int values 

Note that in C++, the compiler must know the value of N at the time of compiling.


DayOfWeek currentDay; // what does this do? Does it plug current day into dayofweek?
This declares the existence of an object of type DayOfWeek, named currentDay. Compare with this:
int x; // declares the existence of an object of type int, named x
Last edited on
Well your code doesn't really do anything right now. There aren't any inputs nor are there any outputs.

DayOfWeek is an enum. That means that you can use Su, Mo, Tu etc instead of using numbers representing the days of the week.

As for your error. You don't define week[N]. We have no idea what 'type' it is. I assume that you want to make it int, unsigned, short or maybe even char. It doesn't really matter which you use.

DayOfWeek currentDay; makes an enum object called currentDay which can be used to call the different enum values. I'm not sure that it really serves a purpose here.
Declare an array of floating point elements called week that can be referenced by using any day of the week as a subscript assume sunday is the first.


Okay well have I at least done this? How would I check? Can I create like a cin and input like "0.0" and have it display in a cout Su? I am sorry. I am relatively new to this. This is a hw question. I could just hand it in now, but it I would rather fully understand my code before hand. Thanks so much for your help.
Also I am getting an error on this sign "{".
week[N] = {//<-here 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
error expected an expression.
How should I fix this?
Thanks.
Last edited on
Hate to bump but I have to hand this in a few hours :(. Just wandering if someone could steer me in the correct direction fixing the above errors and possibly answering my questions.

Thanks so much.
It's becasuse you haven't defined a type for week.

Replace

week[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; // error week is undefined
with
int week[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; // error week is undefined
Topic archived. No new replies allowed.