Question

Create the necessary functions to make the guessing game work. C Language not C++ #include <stdio.h>...

Create the necessary functions to make the guessing game work. C Language not C++

#include <stdio.h>
#include <time.h>

#define MAX_TRIES 10

int getRandomNumber();
char playGame();
char playAgain();

int main(){

start_game:
    
    int num = getRandomNum();
    char play_again = playGame();
    if (play_again == 'Y' || play_again == 'y'){
        goto start_game;
    }
    printf("Bye");
    return 0;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

@MohammedAli7/UnlinedIdealisticconfigfiles C No description share + new repl my repls languages gg talk MohammedAl.. game jom@MohammedAli7/UnlinedIdealisticconfigfiles C No description share + new repl my repls languages gg talk MohammedAl.. game jom

code:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define MAX_TRIES 10

#define MAX 100

#define MIN 1

int getRandomNumber();

char playGame(int num);

char playAgain();

int main(){

int num;

char play_again;

start_game:

num = getRandomNumber();

//pass the value to check

play_again = playGame(num);

if (play_again == 'Y' || play_again == 'y'){

goto start_game;

}

printf("Bye");

return 0;

}

int getRandomNumber(){

//make it random

srand(time(0));

//generate random number between max and min values

return (rand() % (MAX - MIN + 1)) + MIN;

}

char playGame(int num){

int entered;

int tries = MAX_TRIES;

//try untill tries left

while(tries){

printf("\nEnter your Number : ");

scanf("%d",&entered);

if(num == entered){

return playAgain();

}else{

tries--;

if(!tries)

break;

printf("\nYou have %d tries left",tries);

}

}

return playAgain();

}

char playAgain(){

char ch;

printf("\nWanna play again (y/n): ");

scanf(" %c",&ch);

return ch;

}

Add a comment
Know the answer?
Add Answer to:
Create the necessary functions to make the guessing game work. C Language not C++ #include <stdio.h>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate...

    #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int number;     scanf("%d", &number);     if (number % 2 == 0) {         printf("Even\n");     }     else {         printf("Odd\n");     }     return 0; }

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5;...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5; int main() { int number; scanf("%d",&number); while (number < limit){ number++; printf("%d",number); } return 0; }

  • Plz use c language "Simon Says" is a memory game where "Simon" Outputs a sequence of...

    Plz use c language "Simon Says" is a memory game where "Simon" Outputs a sequence of 10 characters (R. G. B. Y) and the user must repeat the sequence Create a for loop that compares the two strings starting from index 0 For each match add one point to user Score Upon a mismatch, exit the loop using a break statement Ex The following patterns yield a user Score of 4: simon Pattern: R, R, G, B, R, Y, Y,...

  • can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf...

    can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf format dont worry about the answers i have down Q3, What is the output of the program shown below and explain why. #include #include <stdio.h> <string.h> int main(void) ( char str[ 39764 int N strlen(str) int nunj for (int i-0; i t Nǐ.de+ printf(") num (str[] 'e); I/ digits range in the ASCII code is 48-57 if (nue > e) f 9 printf( Xdin,...

  • Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public...

    Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public class Project2 { //Creating an random class object static Random r = new Random(); public static void main(String[] args) {    char compAns,userAns,ans; int cntUser=0,cntComp=0; /* * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner(System.in);       System.out.println("*************************************"); System.out.println("Prime Number Guessing Game"); System.out.println("Y = Yes , N = No...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i...

    MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function

  • please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then...

    please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file. (on separate lines) Write the number of guesses to the file at the end of the game. After the game is finished, ask the user if they want to play again. If 'n' or 'N' don't play again, otherwise play again! NOTE: your file should have more than one game in it if the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT