猜猜数字游戏缺少一个循环

时间:2014-01-24 00:24:36

标签: c cs50

我试图做一个“猜数字”游戏,该游戏将使用验证来查看该数字是低,高还是等于随机数。我想做一个循环验证,说明数字是否很高并再试一次!

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <cs50.h>
int
main(void)
{
    srand(time(NULL));
    int skittles = rand() % 1024;
    printf("%d\n", skittles);
    printf("choose a number betwen 1 to 1024\n");



    int numpessoa = GetInt();

    printf("%d\n", numpessoa);

if (numpessoa < skittles)
{
    printf("numpessoa < skittles");
    numpessoa = GetInt();
}

if (numpessoa > skittles)
{
    printf("numpessoa > skittles");
    numpessoa = GetInt();
}

if (numpessoa == skittles)
{
    printf("numpessoa == skittles");
}
return 0;
}

1 个答案:

答案 0 :(得分:2)

如果这是一个家庭作业,你不应该直接问它的解决方案。 我只能提供一些伪代码。

loop forever 
    get user's guess
    check guess against answer
        guess differs answer ,then provide some hints 
        guess equals answer,tell user he/she is right and break out of this loop

您的代码中还有另一个错误。 1024模数的随机整数介于0和1023之间。