Cycle-20. Guess number Games (15)

Source: Internet
Author: User

Guess the number game is to make the system randomly produce a positive integer within 100, the user enters a number to guess, you need to write a program automatically compare it with the randomly generated guessed number, and the hint is big ("Too big"), or small ("Too small"), equal to guess. If guessed, the program is closed. The program also requires the number of statistical guesses, if 1 times to guess the number, the hint "bingo!" If the number is guessed within 3 times, it prompts "Lucky you!" If the number is more than 3 times but is within N (>3) (including nth), it prompts "good guess!" If you don't guess more than n times, prompt "Game over" and end the program. If the user enters a negative number before reaching n times, it also outputs "Game over" and ends the program.

Input format:

The input first line gives 2 positive integers not exceeding 100, which are the random number generated by the system, and the maximum number of guesses N. Each row is then given a user's input until a negative number appears.

Output format:

Output each time you guess the corresponding result in a row until the output guesses the right result or "Game over" ends.

Input Sample:

58 47050565860-2

Sample output:

Too Bigtoo Smalltoo Smallgood guess!
#include <iostream>#include<stdio.h>#include<math.h>#include<string>#include<stdlib.h>intMain () {intNum,n; scanf ("%d%d",&num,&N); inttemp; scanf ("%d",&temp); intCount=1;  while(temp>=0)    {        if(temp>num) printf ("Too big\n"); Else if(temp<num) printf ("Too small\n"); Else         {            if(count==1) {printf ("bingo!\n"); return 0; }            Else if(count<=3) {printf ("Lucky you!\n"); return 0; }            Else if(count<=N) {printf ("Good guess!\n"); return 0; }        }                if(++count<=N) {scanf ("%d",&temp); }        Else{printf ("Game over\n"); return 0; }    }        if(count<n) printf ("Game over\n"); return 0;}

Cycle-20. Guess number 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.