Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this problem using C programming, you will generate a random number, make a

ID: 3815822 • Letter: F

Question

For this problem using C programming, you will generate a random number, make a guess until you guess correctly. Each time the statistics will be written to a file. For one set of games you will make a guess until you guess correctly. For the second set you will receive an indication of whether you guess was too high or two low. There will be one file ‘straight.txt’ with one line with each count, and another file ‘hints.txt’ with one line with each count. After both sets of games are finished, the program will read straight.txt and print the number of games, total guesses and average with labels. Then it will read hints.txt and print the same information with a label.You will use rand to get a number n. Then the user types in a guess, if the guess is out of range it is ignored, else if is correct a count of guesses is printed to the screen and a file.Each incorrect guess is printed in the correct postion of a line.If the straight version just the guess is printed. If the hints version the printed number is negative if too low and positive if two high.

There will be four constants, you must use these everywhere in your code
#define MAX 16
#define GAMES 8
#define STRAIGHT "straight.txt"
#define HINTS "hints.txt"

At the top of the file.
Screen view for user.
At the start of striaght games it will print
Straight 1 – 16 (if MAX is set to 16)
Then for each game it will print
Game 1 or 2 or what ever
Each guess will be a number line with either 4 blanks or the quess
For the hints the same first line for all the games and the Game 1 2 or what ever for each game
The number line will be blanks except the the guess, if too low the guess is negative
After both sets of games are over, read and print the statistics for each type of guesses.
The must be only one (1) variable for the FILE. Open it to write it , then close it and open another file using the same variable.
All variables must be defined BEFORE ANY CODE. No variables defined in for loops only at the top of main.
You must use a for loop to control the number of games for straight and hints.
You must use a do while loop to read the input until it is in range.
You must use a for loop to print the number line with a %4d format
You must use a do while loop around read guess print result while not equal to n.
You must use while loops to read the statistics from straight.txt and hints.txt that can handle any number of lines including an empty file. Your average must be able to handle no lines in the file.

Explanation / Answer

Answer:

Random number guessing game:

#define_CRT_SECURE_NO_DEPRECATE

#include<stdio.h>

#include<time.h>

#include<stdlib.h>

#define MAX16

#define MAXGAME8

void MakeFile();

int Play(int answer);

int GetGuess();

int CmpareGuess(int Guess,int answer);

int numGuesses=0;

int main()

{

    int gamesTPlay=0;

    i=0;

    int answer=0;

       //display instructions

       printf("Welcome t number Guess These are the instructins: First you will need to enter of games to play1-12 you will be prompted to start guessing for a number between 1-8 when you guess the corrct number the game is over you only have 6 chances per game to guess the correct number ");

   MakeFile();      

       printf("please enter the number of games to play(1-8game). ");

       scanf_s("%d",&gamesToPaly);

        printf(" Lets play game 1!! ");

        printf(" remember you nly have 8 guesses to get the correct number ");

        for(i=0;i<gamesToPlay;i++)

        {

            printf("plese guess a number betweem 0 to 16: );

            numGuesses=Play(answer);

        }

        return 0;

   }

   int Play(int answer)

    {

       int guess=0;

       int numGuesses=0;

       do

         {

              guess=GetGuess();

              CompareGuess(guess,answer);

               numGuesses=numGuesses+1;//increases number of guesses made

         }

      while(numGuesses<MAXGUESSES);

        return numGuesses;

    }

void MakeFile()

     {

         int i=0;

         int num;

          srand(time(NULL));//seeds the number generator to randomize

          for(i=0;i<20;i++)

              {

                num=rand()%MAX+1;//calculates a random number from 1 to 16

              }

   }

   int GetGuess()

     {

        intguess;

          scanf_s("%d",&guess);

           return guess;

   }

   int CmpareGuess(int guess,int answer)

     {

       int compare;

       if(guess>answer);

         printf("guesses too high try again");

         return compare;

}

       return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote