04-4. Guess digital games (15)

Source: Internet
Author: User

A number-based game randomly generates a positive integer of less than 100. If you enter a number to guess it, you need to write a program to automatically compare it with the number of randomly generated guesses, and the prompt is "too big", or "too small", which means you have guessed it. If you guessed it, end the program. The program also requires statistics on the number of guesses. If this number is guessed once, "Bingo!" is displayed !"; If you guess the number within three times, the system prompts "Lucky you !"; If you have guessed the number more than 3 times but within N (> 3) times (including N times), the message "Good guess!" is displayed !"; If you haven't guessed it more than N times, the system prompts "game over" and ends the program. If you input a negative number before n times, the system also outputs "game over" and ends the program.

Input Format:

The first line of the input is a positive integer of no more than 100, which is a random number generated by the system and the maximum number of guesses n. Then, each row provides a user input until a negative number is displayed.

Output Format:

Output the result of each guess in a row until the result of the guess or "game over" is output.

Input example:

58 47050565860-2

Output example:

Too bigToo smallToo smallGood Guess!
 

Note: you do not need to generate a random number on your own. You can define a random number and guess it yourself. You can also output a large number of outputs based on the number of guesses and whether or not to guess. You need to be patient.

#include "stdio.h"//#include "stdlib.h"//#include "time.h"int main(){    int n,N,x,i,count=0;    scanf("%d %d",&n,&N);    scanf("%d",&x);    if(x==n)    {        printf("Bingo!\n");        count++;        goto out;    }    else if(x<0)    {            printf("Game Over\n");            count++;            goto out;    }    else    {        for(i=1;i<4;i++)        {                        if(x<0)            {                printf("Game Over\n");                count++;                goto out;            }            else if(x>n)            {                printf("Too big\n");            }            else if(x<n)            {                printf("Too small\n");            }            else            {                printf("Lucky You!\n");                count++;                goto out;            }            count++;            scanf("%d",&x);        }        for(i=4;i<=N;i++)        {            if(x<0)            {                printf("Game Over\n");                count++;                goto out;            }            else if(x>n)            {                printf("Too big\n");            }            else if(x<n)            {                printf("Too small\n");            }            else            {                printf("Good Guess!\n");                count++;                goto out;            }            count++;            scanf("%d",&x);        }        printf("Game Over\n");    }out:        return 0;}

04-4. Guess digital games (15)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.