Getting an error compiling this header

Hey all, thanks for being here to help all us beginners! I keep getting an error stating
"die.h:11:11: error: expected unqualified-id before "[" token

any help would be great i can't figure it out!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctime>


using namespace std;


class cast[6]
{

	srand(time(0));
	int cast = rand() % 6 + 1;  

	return 0;

};

Line 11: This looks like a class declaration. What is [6] supposed to be? You can't put a subscript or dimension there. Why do you have class here?

Lines 14-17: These lines belong in main(), not in a class declaration.

Line 15: You can't assign your calculation to a class name.

You probably want something more like this:
1
2
3
4
5
6
7
8
9
10
#include <ctime>
#include <cstdlib>
using namespace std;

int main () 
{   srand(time(0));
	int cast = rand() % 6 + 1;  

	return 0;
}

Thanks for the input! So, it is part of a project I am supposed to make a "fishing" game including a "cast" or "die" class. So, from what I am getting from what you responded, I figure I did things backwards then if this is my main cpp file?

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <die.h>
#include <cmath>

using namespace std;

int main()

{

	double score;
	string choice;
	bool playAgain;
	


	{

		cout << "Please type 'cast' to cast your line and catch a fish! " << endl;
		cin >> choice;

		if (choice != "cast" && choice != "Cast" && choice != "CAST")
		{

			int cast;
			
			}

		if (cast == 1)
		{
			score++ 1;
			cout << "Oh...wow...you caught a boot, great fishin there... " endl;
			cout << "Your score is: " score << "!" endl;
					}
	
		if (cast == 2)
		{
			score++ 2;
			cout << "Not bad, you caught a Minnow." endl;
			cout << "Your score is: " score << "!" endl;
		}

		if (cast == 3)
		{
			score++ 3;
			cout << "You caught a Large Mouth Bass, good job!" endl;
			cout << "Your score is: " score << "!" endl;
		}

		if (cast == 4)
		{
			score++ 4;
			cout << "Dang grrrl, you caught a Mako Shark!  Get down with yo bad self!" endl;
			cout << "Your score is: " score << "!" endl;
		}

		if (cast == 5)
		{
			score++ 5;
			cout << "Holy hell!  You caught a Killer Whale with a fishing pole!?!?  Call the media!" endl;
			cout << "Your score is: " score << "!" endl;
		}

		if (cast == 6)
		{
			score++ 6;
			cout << "YOU CAUGHT A *#&^#&^#(&(*$&#@ MEGALODON!  YOU ARE KING OF THE WORLD!"
			cout << "Your score is: " score << "!" endl;
		}


		{
			cout << "Would you like to play again? Yes/No" << endl;
			cin >> choice;

			if (choice != "Yes" && choice != "Y" && choice != "yes")
			{
				playAgain = true;
			}

			if playAgain = true
			{
				int cast;
			}
		}

		return 0;


	}


	
}
including a "cast" or "die" class.

I see no cast or die class.

Other comments.
Line 15: score is an uninitialized variable (garbage). You probably want score to be an int, not a double.

Line 29: You're declaring a variable (cast), but it goes out of scope at line 34. Move it to line 14.

Line 32: This is where you want your random calculation.

Line 35,42,49,56,63,70: Syntax problem with these lines. You either need to increment score, or add a value to it.
1
2
3
4
 
  score++;  //  Increment score
// or
  score += 1;  //  Add a value to the score 


Line 82: Your logic is reversed. If line 80 is true, then the user does not want to continue and playAgain should be false.

Line 83: playAgain wasn't initialized, you need to set the true condition.
80
81
82
83
  if (choice == "Yes" || choice == "Y" &|| choice == "yes")
    playAgain = true;
  else 
    playAgain = false;


Line 85: You're using the assignment operator (=), not the comparison operator (==). The if statement needs () around the condition.

Line 87: Ditto line 29.

And finally, you need a loop of some sort to play another round of the game.



Topic archived. No new replies allowed.