Okay, so I had to create a program that would take a number in the range of 0 to 6 and a second number in the range of 1 to 366 as input. The first number represents the day of the week on which the year begins, where 0 is Sunday, and so on. The second number indicates the day of the year. The program then outputs the name of the day of the week corresponding to the day of the year.
I think I have the code down, but I'm getting one tiny error with reference to the dayOfYear = (DOY + DOW -1) % 7 I had to use. It's giving me this error
1>c:\documents and settings\jolie elliott\my documents\visual studio 2008\projects\h04\h04.cpp(32) : error C2296: '%' : illegal, left operand has type 'float'
#include <iostream>
usingnamespace std;
int main ()
{
float DOW; // For the day of week the year began
float DOY; // For the day of the year
float dayOfYear; // Output data for day of year
bool dataAreOK; // True if data is within the range of 1-366
// Prompts user for what day of the week the year begins on
cout << "This will represent what day the year began on. Please enter a whole number from 0-6. 0 represents Sunday and 6 represents Saturday." << endl;
cin >> DOW;
// Prompts user for the day of the year
cout << " Please enter a whole number from 1-366 to represent the day of the year you wish to display." << endl;
cin >> DOY;
// Test Data
if (( DOW < 0 || DOY > 6) || (DOY < 1 || DOY > 366))
dataAreOK = false;
else
dataAreOK = true;
if (dataAreOK)
{
// Calculates the day of the year
dayOfYear = (DOY + DOW -1) % 7;
// Prints the day of the year
if (dayOfYear == 0)
cout << "Sunday" << endl;
elseif (dayOfYear == 1)
cout << "Monday" << endl;
elseif (dayOfYear == 2)
cout << "Tuesday" << endl;
elseif (dayOfYear == 3)
cout << "Wednesday" << endl;
elseif (dayOfYear == 4)
cout << "Thursday" << endl;
elseif (dayOfYear == 5)
cout << "Friday" << endl;
elseif (dayOfYear == 6)
cout << "Saturday" << endl;
}
else
cout << "invalid data; Day of the year and day of the week must be within margins." << endl;
return 0;
}
I'm not really seeing what I did wrong. Any suggestions?