1. 程式人生 > >猜數字(C語言隨機生成1-100)

猜數字(C語言隨機生成1-100)

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
    char next;
    int shu,shu1;
    do
    {
        shu=rand()%100+1;
        system("cls");
        printf("請輸入一個1-100的數: ");
        scanf("%d",&shu1);
        getchar();
        while(shu1!=shu)
        {
            if(shu1<shu)
               {
                    printf("小了\n再輸入一個數吧 ");
                    scanf("%d",&shu1);
               }
            if(shu1>shu)
               {
                   printf("大了\n再輸入一個數吧 ");
                   scanf("%d",&shu1);
               }
        }
        printf("恭喜你,猜對了!!!\n");
         getchar();
        printf("還要玩嗎?y/n\n");
        next=getchar();
        getchar();
    }
    while(next=='y'||next=='Y');
}