Computing.Net > Forums > Programming > C Programming Problems

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C Programming Problems

Reply to Message Icon

Name: JohnNakumara
Date: November 9, 2005 at 22:44:12 Pacific
OS: Windows XP
CPU/Ram: 2.4Ghz/512MB
Comment:

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);

}



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 10, 2005 at 03:05:49 Pacific
Reply:

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


0

Response Number 2
Name: JohnNakumara
Date: November 13, 2005 at 23:06:04 Pacific
Reply:

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?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C Programming Problems

C Programming Problem , www.computing.net/answers/programming/c-programming-problem-/942.html

C Programming Problem www.computing.net/answers/programming/c-programming-problem/1268.html

problem in compiling c program www.computing.net/answers/programming/problem-in-compiling-c-program/7435.html