My program needs to have a declared struct called DayOfWeek that holds the variables dayName(string) and rainAmount(double)
I've done that part and now the prompt tells me that i must create an array of structs that i presume is for the next step following that.
"Create another function to prompt the user to enter the rainfall amount for each day of the week. Pass your array of structs to a function. Note, that day of the week should not be hard-coded in cout << “Enter the rainfall (in inches) for Monday”, instead use a for loop and cout << “Enter the rainfall (in inches) for” << day[i].dayName;"
My problem is that i'm not sure how to create a function that would display the day name without putting dayName from the DayOfWeek struct into a simple array. here's what i have so far as the struct and declaration of the array of structs. i'm not sure if it's correct.
i just input 1-7 in numerical order for the amount of inches
Enter the rainfall(in inches) for Monday: 1
Enter the rainfall(in inches) for Tuesday: 2
Enter the rainfall(in inches) for Wednesday: 3
Enter the rainfall(in inches) for Thursday: 4
Enter the rainfall(in inches) for Friday: 5
Enter the rainfall(in inches) for Saturday: 6
Enter the rainfall(in inches) for Sunday: 7
void getRainAmountdata(DayOfWeek[] days)
{
for (int i = 0; i < NUM_DAYS_OF_WEEK; i++)
{
// get your data here -> days[i].dayName
}
}
int main()
{
getRainAmountdata(day);
// display your data
}
struct DayOfWeek
{
string dayName;
double rainAmount;
};
// then create an array of DayOfWeek objects like this:
constint NUM_DAYS_OF_WEEK = 7;
DayOfWeek day[NUM_DAYS_OF_WEEK];
Now essentially you have 7 objects of type DayOfWeek. Each object has dayName field. You need to fill in the variable with a day of the week for each object.
under the number 0, it told me that the size of the array must be bigger than zero, and under the (.) symbol, it told me that it expected a ';'
when i went and created the second object, under day, it told me that it this declaration has no storage class or type specifier.
i'm not sure if maybe i formatted the objects wrong or if maybe they are supposed to be declared in the structure.
i apologize for asking some many questions, we're just covering structs and i'm still a bit unsure why certain things aren't working
Well when i wrote the first statement, it gave me syntax errors so i didn't write in the rest of the remaining days. And oh i see! Thank you for the help!
Your function getRainAmountData should be getting the array 'day' and its size. You are trying to access the array in the function but haven't passed it in.
1 2 3 4 5 6 7 8
void getRainAmountdata(DayOfWeek day[], constint NUM_DAY_OF_WEEK)
{
for (int i = 0; i < NUM_DAY_OF_WEEK; i++)
{
cout << "Enter the rainfall(in inches) for " << day[i].dayName << ": ";
cin >> day[i].rainAmount;
}
}
Then in main you should call the function like this: