This is Homework
So for one of my projects, I have to make a game of scrabble. The main issue I have is when I randomize a set of 7 characters, I get 7 random symbols. A question mark with the prism behind it. I think this might be an issue with memory, but I have no clue on how to fix it. I'll have part of my program below:
int arr[N];
const char let[] =
{'K' , 'J' , 'X' , 'Q' , 'Z' , 'B' , 'C' , 'M' , 'P' , 'F' , 'H' , 'V' , 'W' , 'Y' , 'G' , 'L' , 'S' , 'U' , 'D' , 'N' , 'R' , 'T' , 'O' , 'A' , 'I' , 'E'};
const int freq[] =
{ 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 3 , 4 , 4 , 4 , 4 , 6 , 6 , 6 , 8 , 9 , 9 , 12 };
unsigned index = 0;
for(int i = 0 ; i < 26 ; i++) {
for(int f = 0 ; f < freq[i]; f++) {
arr[index++] = let[i]; //All the 96 letters are stored in let[i]
//printf("%c " , let[i]); // Created the letter bank for all the letters
} }
int letter = 0;
printf("Your letters are: ");
for(int l = 0; l < 7; l++){
srand((unsigned) time(NULL));
letter = rand() % 96;
printf("%c ", let[letter]); }
So in a game of scrabble each letter has different frequencies. That's what the freq array is used for. There are 96 total possible characters for a game of scrabble and all those letters are stored in the array let[i]. So for my randomizer that starts from "int letter = 0), I have a loop to make it so the user will get 7 letters back. I have mod 96 because that's how many possible letters there are in a game of scrabble. The issue is the print statement at the end is just giving me random characters. Any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire