Code:
// Note that all of my comments appear *above* the applicable line(s) of code!
#include <stdio.h>
#include <time.h>
// For "srand()" and "rand()", be sure to #include <stdlib.h>
// Your function arguments should have names, not just data types
int score(int []);
void get_letters(int []);
int main () {
// When you're done fixing up the program, get rid of any unused variables.
int selection, points, i;
char letter;
int score = 0;
int playable_letters[7];
// If "word" is a string (not just a single character), it should be declared
// as an array of characters. It must be large enough to hold the maximum
// amount of characters you expect. If it's to be used as a string, it should
// be one greater than the max characters you expect (to hold the null char).
char word;
printf("Welcome to Scabble Mania!\n");
printf("Here are your letters!\n");
get_letters(playable_letters);
for (i=0; i<7; i++) {
printf("%c\n", playable_letters[i]);
}
printf("Please enter your word\n");
// You should be scanning for a string (%s) here.
// Note my comments above your declaration of "word" above.
scanf("%c", word);
// This line does nothing. You are counting the score in the variable
// "points," so rid of the unused variable "score".
// Also note that the "score()" function only checks one letter at a time.
// I'd recommend making a loop here that cycles through each character,
// passing it to the function, and keep a running total of "points" for
// for each iteration. Be sure to initialize "points" to zero beforehand!
score;
printf("Your score is %d", points);
return 0;
}
// Consider changing argument to a single character, as mentioned above.
int score (int[]) {
int points;
// The value of "letter" should be passed to the function in its argument
// list, not declared here within the function.
char letter;
switch (letter) {
case 'A':
case 'E':
case 'I':
case 'L':
case 'N':
case 'O':
case 'R':
case 'S':
case 'T':
case 'U':
points = 1;
break;
case 'D':
case 'G':
points = 2;
break;
case 'B':
case 'C':
case 'M':
case 'P':
points = 3;
break;
case 'F':
case 'H':
case 'V':
case 'W':
case 'Y':
points = 4;
break;
case 'K':
points = 5;
break;
case 'J':
case 'X':
points = 8;
break;
case 'Q':
case 'Z':
points = 10;
} // <--- added closing brace for "switch" statement body
// You should be returning the value of "points" here.
// Note that this variable "points" is not the same as the
// "points" variable in "main()" (they are of different scope).
return;
}
// This is not how you declared the function up top.
// I'd recommend changing both the declaration and
// definition to "void get_letters(int letters[])".
void get_letters(int letters [7]) {
// "srand()" should only be called once in the program - you are doing this
// correctly, but it's common to place it near the beginning "main()"
srand(time(0));
int i;
int temp;
// You want "%26" here.
// Also, '+' has greater precedence than '%', so use parenthesis to ensure
// ensure this expression is evalued correctly:
// "( rand()%25 ) + 65;
letters[0] = rand ()%25 + 65;
int check;
for (i=1; i<7; i++) { // <--- added opening brace for "for" body
check = 1;
while (check == 1) {
// see notes for "rand()" a few lines up
temp = rand()%25 + 65;
if(temp != letters[i-1]) {
letters[i] = temp;
check = 0;
} // <--- You want to end the "if" body before the "break"
break;
}
}
}
// <--- removed extra brace that was here