Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having problems filling in certain parts of a program that I have. This program is designed to be a guessing game where the computer generates 4 random letters and you enter 4 letters to try to guess what the letters are. If you guess a letter right, it will tell you that you have a correct letter guessed right, but might be in the wrong position of where the computer generated it's 4 letter, or it will tell you that you have one letter correctly guessed in the right position.
All the codes I am having problems with are denoted by the comment blocks.
Thanks for your help.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>#define ARRAYSIZE 4
#define PEGSIZE 5
#define NEWLINE '\n'void main(void)
{
char pegvalues[PEGSIZE]={'r','g','b','y','o'};
char guess[ARRAYSIZE+1],mystery[ARRAYSIZE];
char ch;
int i,j,trys=0;
int not_ok;
int correct_position, wrong_position;srand(time(NULL));
i = 0;
while (i < ARRAYSIZE) {
mystery[i] = pegvalues[rand()%PEGSIZE];
i = i + 1;
}printf("Welcome\n");
printf("Enter 4 letters.\n");do {
trys = trys + 1;do {
not_ok = 0;
printf("\nEnter your guess (max %d chars.): ",ARRAYSIZE);
i = 0;/* code here to read in the guess string */
if (i != ARRAYSIZE) {
printf("\nThe entered guess must have exactly");
printf(" %d characters, re-enter\n",ARRAYSIZE);
not_ok = 1;
}
else {
guess[i] = '\0';
}
} while (not_ok)i = 0;
correct_position = 0;/* code here to find exact matches in the two arrays */
if (correct_position == ARRAYSIZE) {
printf("You guessed correctly!!\n");
printf("It took %d try(s)\n",trys);
}else {
wrong_position = 0;
i= 0;
while (i < ARRAYSIZE) {
/* code here to find wrong positions.*/
i = i + 1;
}/*code to convert both arrays to lowercase */
printf("Guess: %s ",guess);
printf("Correct position: %d ",correct_position);
printf("Wrong position: %d\n",wrong_position);}
} while (correct_position != ARRAYSIZE);
}

I got this error:
Error guess.c 52: Do-while statement missing ; in function main
What did you get?
If at first you don't succeed, you're about average.M2

the problem of my program was i cannot get 4 others parts of my program since i've gotta all the rest, any suggestions anyone?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |