EXPLAIN LINE 11

1: #include <iostream.h>
2: int main()
3: {
4: enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Â_Saturday };
5:
6: Days DayOff;
7: int x;
8:
9: cout << "What day would you like off (0-6)? ";
10: cin >> x;
11: DayOff = Days(x);
12:
13: if (DayOff == Sunday || DayOff == Saturday)
14: cout << "
You’re already off on weekends!
";
15: else
16: cout << "
Okay, I’ll put in the vacation day.
";
17: return 0;
18: }

I don’t understand line 11, especially Days(x). plz explain it fully!

Ok so Days(x) means your calling a function called days and passing x as a parameter. Since you don’t have a function called days of course your going to get a compile error. Instead you are suppose to do days[x] which will call the xth element of the array days. Also Im pretty sure #include <iostream.h> is wrong, if your calling a header file you do #include “somefile.h” but if your importing the iostream library just do #include

Another thing is when do your cout statements you can always do:
cout << “I chose to take” << n[x] << “off.” << endl;

instead of using those slashes and stuff for a new line.

I didn’t get a compile error… it runs fine. The enum makes a data type or (function?) something called Days, which is why it says Days(x). But I don’t understand what Days(x) does… does it return a value the same type as daysoff?

Show me the output and I’ll see if I can work out what’s happening. Also what compiler are you using? c++ is such a fucked language since shit can vary from compiler to compiler which is why java is your best friend.

I use G++
output: Output: What day would you like off (0-6)? input: 1

output: Okay, I’ll put in the vacation day.

Output: What day would you like off (0-6)? input: 0

output: You’re already off on weekends!

Ahh I see, so your declaring a days object, and daysoff=days(x) is just an array reference like I initially said. But… this is the problem you get when using other peoples code. Theres lots of odd secrets in c++ and your just gunna have to learn them the hard way since you seem to refuse to read documentation otherwise you wouldn’t be having this problem:
This is how I would re-write your code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
string days[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
int choice;

cout << "Please input the day you would like to take off from the list:" << days << ". 0 being " << days[0] << " and 6 being " << days[6] << endl;
cin >> choice;
if (days[choice] == "Sunday" || days[choice] == "Saturday")
	cout << "You're already off on weekends" << endl;
else
	cout << "Okay, I'll be expecting not to see you on " << days[choice] << "." << endl;

return 0;
}

Now you have to solutions that solve the same problem, I hope you will be able to learn from this.

ITT tricxta pretends to know what he’s talking about.

Hint: He’s wrong in both terminology and code usage. His code won’t even work correctly.

wouldn’t it be string days(6)?

I want an explaination of what line 11 does. I don’t need to know how to use it.

Sorry for not being a C++ wiz like you. Also I tested that code using a g++ compiler (cygwin) and it worked fine o_0. But… theres no harm in trying to help but there is in being able to help yet not helping imo :0

Hey gllt, why don’t you help?[COLOR=“Silver”]

---------- Post added at 02:28 PM ---------- Previous post was at 02:27 PM ----------

[/COLOR]also, how would I allow the user to input teams with spaces in this code?

[CODE]
//FakeFan by Phoenix Gillis
//This simulates those people who you explain a game to, and they always try to be on your side. AKA your wife.
#include
#include
using namespace std;
int main()
{
string teamOne;
string teamTwo;
int scoreOne, scoreTwo;
cout << "Team one: ";
cin >> teamOne;
cout << "Team two: " ;
cin >> teamTwo;
cout << "Enter score for the " << teamOne << ": ";
cin >> scoreOne;

cout << "Enter the score for the " << teamTwo << ": ";
cin >> scoreTwo;
if (scoreOne > scoreTwo)
cout << "Go " << teamOne << "!!!";
if (scoreOne < scoreTwo)
cout << "Go " << teamTwo << "!!!";
if (scoreOne == scoreTwo)
{
	cout << "What??? It can't be a tie! give me the real score for the " << teamOne << ": ";
	cin >> scoreOne;
	if (scoreOne > scoreTwo)
	cout << "\

Knew it! Go " << teamOne <<"!";
if (scoreOne < scoreTwo)
cout << "
knew it! Go " << teamTwo << “!”;
if (scoreOne == scoreTwo)
cout << "
Wow, it really was a tie!" << endl;
}
cout << "
Thanks for telling me!";
return 0;
}[/CODE]

NVM, I figured out how to have strings with spaces. Instead of using cin >> teamOne; I used getline(cin, teamOne);[COLOR=“Silver”]

---------- Post added at 03:25 PM ---------- Previous post was at 02:28 PM ----------

[/COLOR]I can’t believe I’m being ignored! HMPH!

Lol it was a joke… And don’t you know some c++? I know nalin does…

ITT people comment on other people’s posts instead of helping

I know nothing of this.

Days(x) gets the value in the enumerator “Days” at position “X”, happy? :expressionless:

Thanks downsider, you were the one to answer my question. I think this thread can be closed now.