0

This is where I'm currently at and I've looked up code very similar to this but they all seem to have something different that sets them apart. I feel like my mistake is right in front of me yet I'm too blind to see it.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    srand(time(NULL));

    int rnum = 1 + rand() % 1000;
    int guess = 0;
    char answer;

    printf("Would you like to play (y or n)?\n");
    scanf_s("%c", &answer);

    while (answer == 'y')
    {
        printf("I have a number between 1 and 1000.\n");
        printf("Can you gueess my number?\n");
        printf("Please type your first guess.\n");
        scanf_s("%d", &guess);

        while (rnum != guess)
        {
            if (rnum > guess)
            {
                printf("Too low. Try again.\n");
                scanf_s("%d", &guess);
            }
            else
            {
                printf("Too high. Try again.\n");
                scanf_s("%d", &guess);
            }
        }
        printf("Execellent! You guess the number!\n");
        printf("Would you like to play again (y or n)?\n");
        scanf_s("%c", &answer);
    }
    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
River
  • 5
  • 1
  • 2
    `scanf_s("%c", &answer);`-->`scanf_s(" %c", &answer);` mind the space – user2736738 Feb 04 '18 at 17:41
  • 2
    I hope this question will be closed soon with one the duplicates. Thanks. – user2736738 Feb 04 '18 at 17:41
  • `scanf_s("%c", &answer);` needs a **length** argument. *"Unlike `scanf` and `wscanf`, `scanf_s` and `wscanf_s` require the buffer size to be specified for all input parameters of type c, C, s, S, or string control sets that are enclosed in []. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable."* Please enable compiler warnings. – Weather Vane Feb 04 '18 at 17:49

0 Answers0