problems with arrays, structuures and files in c in the guessing game

Page 1 of 1

0 Replies - 3013 Views - Last Post: 18 October 2012 - 08:21 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=296229&amp;s=b1186b45231c7af775c884904360c805&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 1
• Joined: 18-October 12

problems with arrays, structuures and files in c in the guessing game

Posted 18 October 2012 - 08:21 PM

The Challenge
“Guess the Number”. To play “guess the number”, the user presses start and the phone app chooses a secret number at random between 1 and 32,767 and displays three asterisks (i.e. ***) on the phone screen. The user is then prompted to guess the number chosen by the app repeatedly until the secret number is guessed. If the number entered by the user is the same as the secret number, then the game ends and the app displays
the game statistics.

If the number entered by the user is less than the secret number, the app displays a message saying that the number is too small. If the number entered by the user is greater than the secret number, the app displays a message saying that the number is too big. If the user enters a number that was entered before, the app displays a message that the number was entered already.

When the game ends, the app should display how many tries were taken before the correct number was guessed, how many were too small, how many were too big and how many were repeated numbers. This information is then saved to a file if it beats the previous score. The first time the app is run the file is created and the score is set to 32,767 guesses. If in a subsequent game the user is able to guess the correct number with less tries than the last one stored in the file, the current number of tries, number of big, number of tries too small, number of tries too big and the number of repeated guesses are stored, replacing the previously stored information.

Required
Write the code for the app using the C programming language and make use of the techniques, data types and programming constructs you have learned in Programming II. Specifically, your code should demonstrate random number generation, arrays, structures, and files.
// I had to put the question in, this is a project. what i dont understand now is the array part and the files and structure.... how can you guys help. here is what i have:

```#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

play_game(void);
result(void);

main(void)
{
getch();
}

{
char choice;
printf("\t      ************GREETINGS EARTH LINX**************");
printf("\n\n\t*************WELCOME TO THE GUESSING GAME 2012***********");

printf("\n\n  ------------------------------------------------------------------------  ");

printf("\n\n\t	How to Play: ***********");

printf("\n\n\t      Soooo....Are you ready to play???? [Y/N] ");
scanf("%c",&choice);

if (choice=='Y' || choice=='y')
{
play_game();
}
else if (choice=='N' || choice=='n')
{

printf("\nTHANKS FOR USING THIS PROGRAM....COME AGAIN....BRING A FRIEND!!!!.");
}

}
play_game(void)
{
int number,guess,tries=0;
srand(time(0));
number = rand()% 32767 + 1;

do
{

scanf("%d",&guess);
tries++;

if (guess < number)
printf("\nYour guess is less, than the secret number" );
else
if (guess > number)
printf("\nYour guess is more, than the secret number");
else
printf("\nCONGRATZZZ!!! YOU'VE GOT IT......YAYYYYY!!!!!!");

}while (guess!=number);
printf("\n\nYou guessed it in %d tries", tries);

system("PAUSE");
return 0;
}

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }