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:
#include <iostream>
usingnamespace std;
int main()
{
enum DayOfWeek { Su, Mo, Tu, We, Th, Fr, Sa };
constint 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.
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
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.
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.