猜字游戏,猜中为止不然一直进行

/*
写一个猜字游戏。要求随机生成一个1~20的数字,然后用户输入自己猜的数字,然后输出猜大了,还是猜小了,或者猜中了,如果没有猜中,一直让用户猜下去,猜中位置。

srand((unsigned)time(NULL));//随机种子
n=rand()%(X)                  //n为0-X之间的随机数

*/

#include "stdafx.h"
#include"stdlib.h"
#include <time.h>


void ves1() {
    int n = 0,Num=0;
sihg:
    srand((unsigned)time(NULL));
    n = rand() % (20);
    printf("请输入一个数");
    scanf_s("%d", &Num);
    if (Num==n)
    {
        printf("恭喜猜中了\n");
    }
    else if (Num < n) {
        printf("\n遗憾猜小了\n");
        goto sihg;
    }else if (Num > n)
    {
        printf("\n遗憾猜大了\n");
        goto sihg;
    }
}

int main()
{
    ves1();
    system("pause");
    return 0;
}

 

posted @ 2017-01-19 15:33  WonderfulWorld  阅读(571)  评论(0编辑  收藏  举报