why wont this compile help!

closed account (3hkyhbRD)
hey im learning c++ and for some reason this wont compile and i dont know why can you explain why and how i can fix it?

#include "stdafx.h"

#include <iostream.h>
int main()
{
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Â_Saturday };

Days DayOff;
int x;

cout << "What day would you like off (0-6)? ";
cin >> x;
DayOff = Days(x);

if (DayOff == Sunday || DayOff == Saturday)
cout << "\nYou're already off on weekends!\n";
else cout << "\nOkay, I'll put in the vacation day.\n";
cin.get();
return 0;
}
Posting the compiler's error messages will help.

Based on how I see your code, here are a few suggestions:
1. Instead of #include <iostream.h> , do #include <iostream> .
2. Qualify iostream's members with the "std" namespace. You can do this by adding using namespace std; right before main.
closed account (3hkyhbRD)
ok i did what you said this is my error message

------ Build started: Project: OFFICE, Configuration: Debug Win32 ------
OFFICE.cpp
OFFICE.cpp(18): error C2065: 'Saturday' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

ok here is the code with the stuff you told me to add.

#include "stdafx.h"

#include <iostream>
using namespace std;
int main()
{
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Â_Saturday };

Days DayOff;
int x;

cout << "What day would you like off (0-6)? ";
cin >> x;
DayOff = Days(x);

if (DayOff == Sunday || DayOff == Saturday)
cout << "\nYou're already off on weekends!\n";
else cout << "\nOkay, I'll put in the vacation day.\n";
cin.get();
return 0;
}

You should try learning how to read compiler error messages instead of relying to others. It will help you in the long run.

As you can see, your compiler is telling you:
 
OFFICE.cpp(18): error C2065: 'Saturday' : undeclared identifier


Without even knowing the format of this error message, it clearly says that something is wrong with "Saturday". Checking for "Saturday" words in your code, you are doing:
 
if (DayOff == Sunday || DayOff == Saturday)


But the compiler cannot find this "Saturday" identifier, because in you do not have it in your enum. You enum only provides the following:
 
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Â_Saturday
Last edited on
Topic archived. No new replies allowed.