jeudi 3 novembre 2016

Guessing game - stuck in loop.

I am working on a guessing game program. The main function asks the user to guess a number and if that number does not equal the correct guess, it is sent to a different function that tells the user if that number is too high or too low. The second function then asks the user for another guess and that guess is sent back to the first function.

My code gets trapped in the second function and does not appear to exit it. I'm not sure what to change.

#include <stdio.h>

int guess(int num);

int main(void)
{
    int units;  

    printf("How many legs on a wonderwump??\n");
    scanf_s("%d", &units);
    while (units != 56)
    {
        guess(units);
    }
    printf("Great guess!\n");
    return 0;
}

int guess(int num)
{

    if (num > 56)
    {
        printf("Too high of a guess! Try again!");
    }
    else // (num < 56)
    {
        printf("Too low of a guess! Try again!");
    }

return scanf_s("%d", &num);

}

Aucun commentaire:

Enregistrer un commentaire