HELP! CANNOT UNDERSTAND ERROR MESSAGE!!

Here is the current code i am trying to run. i see nothing wrong with it but the errors are listed below
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
100
101
102
103
104
105
106
107
#include<iostream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

//Declerations
//Question Strings
string a; //Asking if you want to play
string b; //Asking if you want to draw red or blue
string c; //Asking if you want to go back to the menu
string d; //Asking if you want to play again
//Variable Declerations
int r; //Variable With A Random Value
int t; //Variable With Your Total Score
int d; //Pick a deck
int red; //Prepping Red Matrix
int blue; //Prepping Blue Matrix

//Microprogram Declerations
int MAIN();
int PLAY();
void RULES();
void DETERMINE();
void SETVALUES();
void LOSS();

//---------------------------------------------------------------

//Active Play
int PLAY(){
system("cls");
srand ( time(NULL) );
r = rand() % 1 + 0;
cout<<"Your total is "<< t <<"!"<<endl;
cout<<"Pick a deck"<<endl;
cout<<"Red or Blue"<<endl;
cin>> d;
if (d == "Red" || d == "red"){
t = t + red[r];
DETERMINE();
}
if (d == "Blue" || d == "blue"){
t = t + blue[r];
DETERMINE();
}
else
PLAY();
}

//If the player has lost, do this
void loss(){
system("cls");
cout<<"You Have Lost"<<endl;
system("pause");
return;
}

//Algorithim to determine weather or not the player has been stupid enough to lose a game of luck yet.
void DETERMINE(){
if (t > 0)
PLAY();
if (t == 0 || t < 0)
LOSS();
else{
system("cls");
cout<<"FATAL SYSTEM ERROR"<<endl;
system("pause");
return;
}

//Setting the initials Values
void SETVALUES(){
t = 500;
int red[0] = {-50};
int red[1] = {50};
int blue[0] = {-100};
int blue[1] = {100};
}

//Telling the player the rules
void RULES(){
cout<<"The Rules of the game are simple"<<endl;
cout<<"You start out with 500 dollars"<<endl;
cout<<"Draw from either the Red or the Blue deck"<<endl;
cout<<"Each deck has card that either add or subtract from your pool"<<endl;
cout<<"Have Fun!";
cout<<"press anykey to go back to the menu"<<endl;
system("pause");
MAIN();
return;

//Starting Welcome Menu
int MAIN(){
system("cls");
cout<<"Welcome to the Red Blue Card Game"<<endl;
cout<<"Featured in Malcom Gladwell's Blink"<<endl;
cout<<""<<endl;
cout<<"Type Rules to View The Rules"<<endl;
cout<<"Or, Type Play to Play The Game"endl;
if (a == "Rules" || a == "rules")
RULES();
if (a == "Play" || a == "play")
SETVALUES();
}



1>------ Build started: Project: Red Blue Card Game, Configuration: Debug Win32 ------
1>Build started 8/21/2011 7:16:10 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Red Blue Card Game.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> MAIN.cpp
1>MAIN.cpp(17): error C2371: 'd' : redefinition; different basic types
1> MAIN.cpp(13) : see declaration of 'd'
1>MAIN.cpp(34): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>MAIN.cpp(39): error C2088: '>>' : illegal for class
1>MAIN.cpp(40): error C2088: '==' : illegal for class
1>MAIN.cpp(40): error C2088: '==' : illegal for class
1>MAIN.cpp(41): error C2109: subscript requires array or pointer type
1>MAIN.cpp(44): error C2088: '==' : illegal for class
1>MAIN.cpp(44): error C2088: '==' : illegal for class
1>MAIN.cpp(45): error C2109: subscript requires array or pointer type
1>MAIN.cpp(74): error C2601: 'SETVALUES' : local function definitions are illegal
1> MAIN.cpp(61): this line contains a '{' which has not yet been matched
1>MAIN.cpp(83): error C2601: 'RULES' : local function definitions are illegal
1> MAIN.cpp(61): this line contains a '{' which has not yet been matched
1>MAIN.cpp(107): fatal error C1075: end of file found before the left brace '{' at 'MAIN.cpp(83)' was matched
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.20
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Use [code][/code] tags please.

You declare two variables with the identifier 'd', one string, another int.

You don't need a function prototype for main.

Red is not an array (red[r]).

Neither is blue (blue[r]).

You create a couple red and blue arrays (incorrectly) after using the arrays above

1
2
3
4
int red[0] = {-50};
int red[1] = {50}; // red is already declared
int blue[0] = {-100};
int blue[1] = {100}; // as is blue 


play () doesn't return anything (it should return something of type int).

You are missing a brace at the end of DETERMINE

RULES is missing a brace as well.

system("Pause"); already has a message saying to press any key.

You shouldn't call main from another function, that is what the return statement is for, to return something from the current function to the function which calls it.

Your post is really messy, so these are the few that stick out to me. If you would place the code in [code][/code] tags and the errors in [output][/output] tags, it would help greatly as it would be much easier to read. Also lessening the capatalized identifiers would be easier on the eyes as well (for me at least).
I have made all the corrections that i understood. Here is the code, i am still getting a few errors

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
100
101
102
103
104
105
106
107
108
#include<iostream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

//Declerations
	//Question Strings
		string a;	//Asking if you want to play
		string b;	//Asking if you want to draw red or blue
		string c;	//Asking if you want to go back to the menu
		string d;	//Asking if you want to play again
	//Variable Declerations
		int r;		//Variable With A Random Value
		int t;		//Variable With Your Total Score
		string x;		//Pick a deck
		int red;	//Prepping Red Matrix
		int blue;	//Prepping Blue Matrix

	//Microprogram Declerations
		int MAIN();
		void PLAY();
		void RULES();
		void DETERMINE();
		void SETVALUES();
		void LOSS();

//---------------------------------------------------------------

//Active Play
void PLAY(){
	system("cls");
	srand ( time(NULL) );
	r = rand() % 1 + 0;
	cout<<"Your total is "<< t <<"!"<<endl;
	cout<<"Pick a deck"<<endl;
	cout<<"Red or Blue"<<endl;
	cin>> x;
	if (x == "Red" || x == "red"){
		t = t + red[r];
		DETERMINE();
	}
	if (x == "Blue" || x == "blue"){
		t = t + blue[r];
		DETERMINE();
	}
	else
		PLAY();
}

//If the player has lost, do this
void loss(){
	system("cls");
	cout<<"You Have Lost"<<endl;
	system("pause");
	return;
}

//Algorithim to determine weather or not the player has been stupid enough to lose a game of luck yet.
void DETERMINE(){
	if (t > 0)
		PLAY();
	if (t == 0 || t < 0)
		LOSS();
	else{
		system("cls");
		cout<<"FATAL SYSTEM ERROR"<<endl;
		system("pause");
		return;
	}
}

//Setting the initials Values
void SETVALUES(){
	t = 500;
	red[0] = {-50};
	red[1] = {50};
	blue[0] = {-100};
	blue[1] = {100};
}

//Telling the player the rules
void RULES(){
	cout<<"The Rules of the game are simple"<<endl;
	cout<<"You start out with 500 dollars"<<endl;
	cout<<"Draw from either the Red or the Blue deck"<<endl;
	cout<<"Each deck has card that either add or subtract from your pool"<<endl;
	cout<<"Have Fun!";
	cout<<"press anykey to go back to the menu"<<endl;
	system("pause");
	return;
}

//Starting Welcome Menu
int MAIN(){
	system("cls");
	cout<<"Welcome to the Red Blue Card Game"<<endl;
	cout<<"Featured in Malcom Gladwell's Blink"<<endl;
	cout<<""<<endl;
	cout<<"Type Rules to View The Rules"<<endl;
	cout<<"Or, Type Play to Play The Game"endl;
	if (a == "Rules" || a == "rules")
		RULES();
	if (a == "Play" || a == "play")
		SETVALUES();
}



1>------ Build started: Project: Red Blue Card Game, Configuration: Debug Win32 ------
1>Build started 8/21/2011 8:39:30 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\Red Blue Card Game.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1>  MAIN.cpp
1>MAIN.cpp(34): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>MAIN.cpp(41): error C2109: subscript requires array or pointer type
1>MAIN.cpp(45): error C2109: subscript requires array or pointer type
1>MAIN.cpp(77): error C2109: subscript requires array or pointer type
1>MAIN.cpp(77): error C2059: syntax error : '{'
1>MAIN.cpp(77): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(77): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(78): error C2109: subscript requires array or pointer type
1>MAIN.cpp(78): error C2059: syntax error : '{'
1>MAIN.cpp(78): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(78): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(79): error C2109: subscript requires array or pointer type
1>MAIN.cpp(79): error C2059: syntax error : '{'
1>MAIN.cpp(79): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(79): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(80): error C2109: subscript requires array or pointer type
1>MAIN.cpp(80): error C2059: syntax error : '{'
1>MAIN.cpp(80): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(80): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(102): error C2146: syntax error : missing ';' before identifier 'endl'
1>MAIN.cpp(102): warning C4551: function call missing argument list
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.76
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
And you should note that C++ identifiers are case-sensitive

So even after you fix all your syntax errors, your program will fail to link as the required entry-point will not be found. It must be (all lowercase)

1
2
int main()
{


As Danny Toledo said, main does not need a prototype. But MAIN is not main!

And all upper-case identifiers are usually reserved for #defines (and sometimes typedefs). Function names are usually lowercase, lowerCamelCase. or UpperCamelCase (used consistently!).

Andy

P.S. For more info about tags, see "How to use tags"
http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
closed account (zb0S216C)
Errors wrote:
1>MAIN.cpp(41): error C2109: subscript requires array or pointer type
1>MAIN.cpp(45): error C2109: subscript requires array or pointer type
1>MAIN.cpp(77): error C2109: subscript requires array or pointer type (sic)

Your global variable, red, is not an array. Therefore, it's syntactically illegal to use the sub-script ([...]) operator on it.

Errors wrote:
1>MAIN.cpp(77): error C2059: syntax error : '{'
1>MAIN.cpp(77): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(77): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(78): error C2109: subscript requires array or pointer type
1>MAIN.cpp(78): error C2059: syntax error : '{'
1>MAIN.cpp(78): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(78): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(79): error C2109: subscript requires array or pointer type
1>MAIN.cpp(79): error C2059: syntax error : '{'
1>MAIN.cpp(79): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(79): error C2143: syntax error : missing ';' before '}'
1>MAIN.cpp(80): error C2109: subscript requires array or pointer type
1>MAIN.cpp(80): error C2059: syntax error : '{'
1>MAIN.cpp(80): error C2143: syntax error : missing ';' before '{'
1>MAIN.cpp(80): error C2143: syntax error : missing ';' before '}' (sic)

Braces ({...}) cannot be used in this manner. Braces are only used for initialization lists and body scopes. You need to either remove the braces or replace the braces with parentheses. Also, as I said above, you've used red as an array, which it is not.

Errors wrote:
1>MAIN.cpp(102): error C2146: syntax error : missing ';' before identifier 'endl'
1>MAIN.cpp(102): warning C4551: function call missing argument list (sic)

You've forgot to place the << before endl.

Wazzak
Last edited on
EDIT : wow, I must have forgotten to refresh the page or something; I thought there were no replies to this when I posted, but boy, was I wrong.

No need to duplicate the errors already presented by the above posters
Last edited on
GUYS THANK YOU SO MUCH FOR ALL YOUR HELP. THERES JUST A LITTLE BIT LEFT. ONLY ONE TYPE OF ERROR.

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
100
101
102
103
104
105
106
107
#include<iostream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

//Declerations
	//Question Strings
		string a;	//Asking if you want to play
		string b;	//Asking if you want to draw red or blue
		string c;	//Asking if you want to go back to the menu
		string d;	//Asking if you want to play again
	//Variable Declerations
		int r;		//Variable With A Random Value
		int t;		//Variable With Your Total Score
		string x;		//Pick a deck
		int red;	//Prepping Red Matrix
		int blue;	//Prepping Blue Matrix

	//Microprogram Declerations
		int main();
		void play();
		void rules();
		void determine();
		void setvalues();
		void loss();

//---------------------------------------------------------------

//Active Play
void play(){
	system("cls");
	srand ( time(NULL) );
	r = rand() % 1 + 0;
	cout<<"Your total is "<< t <<"!"<<endl;
	cout<<"Pick a deck"<<endl;
	cout<<"Red or Blue"<<endl;
	cin>> x;
	if (x == "Red" || x == "red"){
		t = t + red[r];
		determine();
	}
	if (x == "Blue" || x == "blue"){
		t = t + blue[r];
		determine();
	}
	else
		play();
}

//If the player has lost, do this
void loss(){
	system("cls");
	cout<<"You Have Lost"<<endl;
	system("pause");
	return;
}

//Algorithim to determine weather or not the player has been stupid enough to lose a game of luck yet.
void determine(){
	if (t > 0)
		play();
	if (t == 0 || t < 0)
		loss();
	else{
		system("cls");
		cout<<"FATAL SYSTEM ERROR"<<endl;
		system("pause");
		return;
	}
}

//Setting the initials Values
void setvalues(){
	t = 500;
	red[0] = -50;
	red[1] = 50;
	blue[0] = -100;
	blue[1] = 100;
}

//Telling the player the rules
void rules(){
	cout<<"The Rules of the game are simple"<<endl;
	cout<<"You start out with 500 dollars"<<endl;
	cout<<"Draw from either the Red or the Blue deck"<<endl;
	cout<<"Each deck has card that either add or subtract from your pool"<<endl;
	cout<<"Have Fun!";
	cout<<"press anykey to go back to the menu"<<endl;
	system("pause");
	return;
}

//Starting Welcome Menu
int main(){
	system("cls");
	cout<<"Welcome to the Red Blue Card Game"<<endl;
	cout<<"Featured in Malcom Gladwell's Blink"<<endl;
	cout<<""<<endl;
	cout<<"Type Rules to View The Rules"<<endl;
	cout<<"Or, Type Play to Play The Game"<<endl;
	if (a == "Rules" || a == "rules")
		rules();
	if (a == "Play" || a == "play")
		setvalues();
}


[output]
1>------ Build started: Project: Red Blue Card Game, Configuration: Debug Win32 ------
1>Build started 8/21/2011 9:10:03 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Red Blue Card Game.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> MAIN.cpp
1>MAIN.cpp(34): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>MAIN.cpp(41): error C2109: subscript requires array or pointer type
1>MAIN.cpp(45): error C2109: subscript requires array or pointer type
1>MAIN.cpp(77): error C2109: subscript requires array or pointer type
1>MAIN.cpp(78): error C2109: subscript requires array or pointer type
1>MAIN.cpp(79): error C2109: subscript requires array or pointer type
1>MAIN.cpp(80): error C2109: subscript requires array or pointer type
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.64
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

[\output]
closed account (zb0S216C)
red is not an array. You need to declare it as an array at the point of declaration. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
// Declare an array of 3 integers and initialize each element
// with a random value (hand picked).
int Red[3] = 
{
    37, 29, 28
};

int main( )
{
    // Use the sub-script operator ([...]) to access individual
    // elements of the array.
    Red[0] = 10;
}

Note that indices are zero-based. This means that the first index (first element) is 0, the second is 1, and so on.

Wazzak
Last edited on
its no longer giving me errors messages, but it shuts down immediately before escaping main
heres a copy of main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(){
	system("cls");
	cout<<"Welcome to the Red Blue Card Game"<<endl;
	cout<<"Featured in Malcom Gladwell's Blink"<<endl;
	cout<<""<<endl;
	cout<<"Type Rules to View The Rules"<<endl;
	cout<<"Or, Type Play to Play The Game"<<endl;
	if (a == "Rules" || a == "rules")
		rules();
	if (a == "Play" || a == "play")
		setvalues();
	else
		main();
}

closed account (zb0S216C)
That's because you need to explicitly tell the program to wait. You can do this with either function:

1
2
3
4
5
int Wait( )
{
    std::cin.ignore( std::numeric_limits< std::streamsize >::max( ), '\n' );
    return 0;
}

Or

1
2
3
4
5
int Wait( )
{
    std::cin.get( );
    return 0;
}

The first option requires the user to press enter. The second option requires the user to enter a character then press enter. The choice is yours.

A final note: Never call main( ). Only the operating system should call main( ).

Wazzak
That's because there's no chance for the user to input anything. You need a cin statement to get "rules" or "play"
How does that compile? When I call main () in main, I get:

Error E2120 main.cpp 6: Cannot call 'main' from within the program in function main()


If I try calling it from another function, I get the same error, only "main ()" is replaced by the name of the function trying to call it.

As it has already been stated, you need to get input from the user to determine whether he/ she wants to play or see the rules.

cin.get (); only requires the user to hit enter. If you are getting input data before the use of the function (cin>> and getline as well I think), use cin.clear (); or cin.sync (); (or both) before cin.get ();

A quick jump back to the full code, there is also no need for function prototypes if you define the functions before main (or whatever function will be calling it).
Last edited on
closed account (zb0S216C)
Danny, std::cin.clear( ) only clears the flags set by std::cin; it doesn't actually manipulate the characters within the stream.

I do admit, however, that I was wrong about std::cin.get( ).

Wazzak
Topic archived. No new replies allowed.