Guess game problem | Sololearn: Learn to code for FREE!

0

Guess game problem

I NEED HELP. IM GETTING DOUBLE INPUTS #include <stdio.h> int main() { int g_num=7; int num; int attempts; printf("please guess the number.\n"); for(attempts=5; attempts >= 0; attempts--){ scanf("%d \n", &num); if (num==g_num){ printf("Congratulations \n You have won!!! \n"); break; } else if (num != g_num){ printf("Sorry, your guess was wrong. Please try again \n"); printf("you have %d attempts left \n", attempts); } } return 0; }

2/21/2021 11:21:48 PM

othneillo

3 Answers

New Answer

+1

othneillo it's okay, I also make mistakes a lot lol

+5

You dont need the newline in scanf Format specifier.. Just write scanf("%d", & num);

+3

Thank you so much. cant believe i didnt notice that