Void will not work

closed account (1hv7ko23)
Thank you in advance for any help.

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include<iostream>
#include<string>						
#include<ctime>
using namespace std;

void Spin(int&);          			        	// The void function "Spin" assigns the variable "spinner" a number
void check(int [], int &);


void Spin(int& spinner) 	                		//  Precondition:
{								//     "spinner" equals zero
  srand(time(NULL));						//  Postcondition:		
  spinner=rand()%6+1;						//     "spinner" is assigned a random number between 1-6

								//
}								// The information that was used to make the rand number generator was from
								//        http://www.cplusplus.com/reference/clibrary/cstdlib/rand/


void check(int space[6],int& next)
{
  if (space[1]<100||space[2]<100||space[3]<100||space[4]<100||space[5]<100)          //  Precondition: 
    next=2;									     //
  else										     //  Postcondition:
   next=1;									     //

}


int main()
{
   int space[6];						// "space" keeps track of what space all the players are on the board
   int number;							// "number" is the amount of players that are playing
   int i=0;							// "i" is used in space to determine which player is going
   int spinner;							// "spinner" this gets a random nuber 1-6 and adds it to space
   int win;							// "win" decides whether the program should continue or not
   string answer;						// "answer" has the user input something to continue
   int next=1;						//  After someone wins it stops the next player(s) by going
   cout<<"Enter how many players you want."<<endl;
   cin>>number;							// This intializes all the dimensions of space as zero
   for (i=0;i<number+1;i++)
   {
    space[i]=0;
   }

  cout<<"Everone starts on space 0."<<endl;

   win=1;

   while(win==1)						// This loop keeps going until someone wins
   {
      for (i=1;i<=number;i++)            			//This gives each of the players a turn
      {

        check(space[6],next);
        

        while(next==1)
        {
          cout<<"Player "<<i<<" type something in to continue."<<endl;
          cin>>answer;						//This pauses the program so its not all done in one second
 

           Spin(spinner);					//This calls to the Spin function


          space[i]=space[i]+spinner;				//Adds what the player rolled to their space
          cout<<"Player "<<i<<" spun a "<<spinner<<". "<<endl;
          if(space[i]>100)
          {
          space[i]=100;
          }
          cout<<"You are now on space "<<space[i]<<"."<<endl;

/********************************************************************************/
/*										*/
/*      These if statements are the "chutes" and "ladders" of the program	*/
/*										*/
/********************************************************************************/

          if (space[i]==4)
          {
              cout<<"You donated blood. You advance to space 14."<<endl;
              space[i]=14;
          }
          if (space[i]==9)
          {  
              cout<<"You won the pie-eating contest. You advance to space 31."<<endl;
              space[i]=31;
          } 
          if (space[i]==16)
          {  
              cout<<"You knocked a bookcase over. You go back to space 6."<<endl;
              space[i]=6;
          } 
          if (space[i]==21)
          {  
              cout<<"You won the pet show. You advance to space 42."<<endl;
              space[i]=42;
          } 
          if (space[i]==28)
          {  
              cout<<"You won the lottery! You advance to space 84."<<endl;
              space[i]=84;
           } 
          if (space[i]==36)
          {  
              cout<<"You baked a cake for your mother. You advance to space 44."<<endl;
              space[i]=44;
          } 
          if (space[i]==47)
          {  
              cout<<"You lost your favorite book. You go back to space 26."<<endl;
              space[i]=26;
          } 
          if (space[i]==49)
          {  
              cout<<"You forgot your mother's birthday. You go back to space 11."<<endl;
              space[i]=11;
          }
          if (space[i]==51)
          {
              cout<<"You helped a cat get out of a tree. You advance to space 67."<<endl;
              space[i]=67;
          }
          if (space[i]==56)
          {
              cout<<"You didn't feed your pet. You go back to space 53."<<endl;
              space[i]=53;
          }
          if (space[i]==62)
          {
              cout<<"You failed a big test. You go back to space 19."<<endl;
              space[i]=19;
          }
          if (space[i]==64)
          {
              cout<<"You lost your pet. You go back to space 60."<<endl;
              space[i]=60;
          }
          if (space[i]==71)
          {
              cout<<"You got an 'A' on a big test. You advance to space 91."<<endl;
              space[i]=91;
          }
          if (space[i]==80)
          {
              cout<<"You have discovered a cure for cancer. You advance to space 100."<<endl;
              space[i]=100;
          }
          if (space[i]==87)
          {
              cout<<"You crashed your parents' car. You go back to space 24."<<endl;
              space[i]=24;
          }
          if (space[i]==93)
          {
              cout<<"You broke the TV. You go back to space 73."<<endl;
              space[i]=73;
          }
          if (space[i]==95)
          {
              cout<<"You spilled the paint on the floor. You go back to space 75."<<endl;
              space[i]=75;
          }
          if (space[i]==98)
          {
              cout<<"You caught the flu. You go back to space 78."<<endl;
              space[i]=79;
           }
          if (space[i]>=100)
          {
              cout<<"Player "<<i<<" YOU WIN!"<<endl;
              win=2; 
          }


         if (space[i]>=100)
         {
             space[i]=100;
         }

         next=2;
 
        
        }							// Ends the if statement
       }							// Ends the for statement
     }								// Ends the while statement
   return 0;

   }								// Ends int main 






THE ERRORS ARE:

andlad.cpp: In function ‘int main()’:
andlad.cpp:62: error: invalid conversion from ‘int’ to ‘int*’
andlad.cpp:62: error: initializing argument 1 of ‘void check(int*, int&)’
Last edited on
Line 7 doesn't have a semi-colon
continue is a reservered word. Choose some other variable name.
closed account (1hv7ko23)
Thanks for your help. I updated the program
This error message

andlad.cpp:(.text+0x1e9): undefined reference to `check(int, int&)'


says that you use function check declared as check(int, int&) but you forgot to define it. The problem is that your declaration

void check(int, int&);

and your definition

void check(int space[6],int& next)

do not correspond each other. The definition in fact is equivalent to

void check( int &, int& next)

Do you see the difference?

Inside the main the call

check(space[6],next);


refers to the function

void check(int, int&);

which was not defined because you defined another function namely

void check( int &, int& next)
remove this line, which is located before main, you don't need it, since you're implementing your function before using it, line-wise.

 
void check(int, int&);
He can not remove this line because at first he shall decide which of the two functions he is going to use!
Last edited on
the first one is supposed to be a prototype for the second one. He's not a pro, and he's doing beginners' mistakes. That's why I told him to remove it.
closed account (zb0S216C)
Your prototype doesn't match the definition. The prototype states that the first parameter is a single int, not an array. It should be 1 of these:

A) void check(int [], int &). This is the same as: void check(int *, int &)
B) void check(int(&)[6])

B is a little more advanced.

Wazzak
closed account (1hv7ko23)
Now we just have a dumb error, if you please help me i will be grateful.
closed account (zb0S216C)
Line 55: You're passing an int (not an array) as the first argument of check(). The call should resemble: check(space, next).

Wazzak
Last edited on
closed account (1hv7ko23)
Thanks for all the help!
Topic archived. No new replies allowed.