simple problem

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'


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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>

using namespace 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;

        else if (dayOfYear == 1)
            cout << "Monday" << endl;

        else if (dayOfYear ==  2)
            cout << "Tuesday" << endl;

        else if (dayOfYear == 3)
            cout << "Wednesday" << endl;

        else if (dayOfYear ==  4)
            cout << "Thursday" << endl;

        else if (dayOfYear ==  5)
            cout << "Friday" << endl;

        else if (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?
You can't use % with floats. Speaking of that, why are the floats to begin with? They should be ints IMO.
Last edited on
Yeah I just saw that. I was reading up on the error. Stupid mistake on my part, sorry.
Topic archived. No new replies allowed.