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; }

21st Feb 2021, 11:21 PM
othneillo - avatar
3 Answers
+ 1
othneillo it's okay, I also make mistakes a lot lol
22nd Feb 2021, 3:05 AM
+ 5
You dont need the newline in scanf Format specifier.. Just write scanf("%d", & num);
21st Feb 2021, 11:48 PM
G B - avatar
+ 3
Thank you so much. cant believe i didnt notice that
22nd Feb 2021, 12:46 AM
othneillo - avatar