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;
}
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 usingnamespace std; right before main.
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;
}
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: