I'm learning C++ from a book and the following example doesn't work in codeblocks. My compiler gives an error:
use of enum
'Days'
without previous declaration
Can someone enlight me here?
#include <iostream>
using namespace std;
int main() // main routine
{
int a;
enum Days (zo,ma,di,wo,do,vr,za); // <error here> : use of enum 'Days' without previous declaration
Days today;
today = ma;
if (today == zo || today == za)
cout << "weekend \n"
else
cout << "ohno workday \n";
return 0;
}
You're using enum
incorrectly. Your parentheses should be braces:
enum Days {zo,ma,di,wo,do,vr,za};
Now zo
will be equal to 0, since you didn't explicitly define a value, and each thereafter will be one more than the last.
Also notice (easily, due to syntax highlighting) that do
conflicts with the do
keyword reserved for do...while
statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With