mystery problem array size

there are three different possible sizes for the array 4, 6, or 8. For some reason 4 and 6 work, but not 8. Basically anything 8 and up doesn't work. Heres the code that sets the array size.

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

//the function that sets the array size
int gameLevel(){
   int level, size = 1;
   
   cout << "What level difficulty do you what to play?\n" << "Easy(1), Normal(2), Hard(3): ";
   cin >> level;
   /*while(level != 1 && level != 2 && level != 3){
    cout << "That is not one of the difficulty levels.\n" << "Easy(1), Normal(2), Hard(3): ";
    cin >> level;
    }*/
   cout << "out of loop";
   switch(level){
      case 1:
         cout << "easy";
         size = 4;
         break;
      case 2:
         cout << "normal";
         size = 6;
         break;
      case 3:
         cout << "hard";
         size = 8;
         break;
   }
   return size;
}

//the first bit of main with the function
int main(){
   bool allCorrect = false, get = true;
   ofstream outputFile;
   int theMode, size, numGuesses = 15, playersGuesses = 0;
   
   
   menu();                                      //Menu, choocing game mode
   theMode = gameMode();
   size = gameLevel();

   return 0;
}
The code you posted has no evident problem.

You mentioned something about an array. That's probably your problem. What do you do with the size value once you get it?
it won't take the size though :'(
heres the constructor that uses the size.

1
2
3
4
5
6
7

Colors::Colors(int size, bool duplicates){       //constructor
   kSize = size;
   cDuplicates = duplicates;
   answerArray = new char[kSize];
}
I fixed it. instead of putting 8, I put 1 + 7 and it works. :)
There's no way that was the problem. The compiler sees "8" and "1+7" as exactly the same thing.

What else did you change?
Topic archived. No new replies allowed.