Declare an array of floating point elements?

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 just set up a floating point array like
week[0.0,2.0,3.0, 4.0,5.0,6.0]
then just set up a switch for each case like
switch(week){
case 1 =0
etc.
etc.

Does this sound right?
Thanks.
You can declare an enumeration type and use its enumerators as subscipts.

I do no know English very well but it could look as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
enum DayOfWeek { Su, Mo, Tu,/*other shortened names of days */, Sa };
const int N = Sa + 1;

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

DayOfWeek currentDay;

// some code

switch ( currentDay )
{
case Su:
   week[Su] = SomeValue;
   break;
case Mo:
   week[Mo] = AnotherValue;
// ...
default:
   std::cout << "Invalid day of week\n";
   break;
}
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.
Topic archived. No new replies allowed.