0
C: What can I do in this code instead of calling a function inside another function?
This code is a number guessing game. A random 4-digit number is generated and the user is supposed to guess the number by passing 4-digit number guesses to the program. If any digit is correct, the program will display a + sign in the place value of the digit, and it will display a - sign in place of the falsely guessed numbers. I made the part that generates a random number as a function separate from the function that does the guessing. However, I have to pass the random number to the guessing() function, but that is not possible. How do I change my code to make this possible? The link to the code is attached below. Thank you in advance :) https://code.sololearn.com/cEnKZzgDLTzz
5 Answers
+ 1
Not if you generate the number outside while in main and then never change it.
+ 1
Line 77: use putchar instead of printf. You only want to print a single char, not a string. You get an infinite loop then from the surrounding while. You need to recheck the condition.
0
Why is it not possible? What keeps you from adding another parameter to the guessing function to take the random number?
0
if i do this, my program will guess another number every time the function is called, and the function is supposed to be called every time the user gets the answer wrong
0
I changed my code as per your suggestion, but now I have a single error that won't make my code run. I'd appreciate it if you checked this version of my code