'Function not giving normal output
I am trying to compile my practice on functions. I tried many times to compile this and I bumped into this issue.
Here below is my code:
#include <stdio.h>
int displayFlow();
int main(){
int displayFlow();
}
int displayFlow(){
int try1,try2,try3;
printf("enter any given number...\n");
scanf("%d", &try1);
printf("if u entered above 10, ur out\n...please enter another guess...\n");
scanf("%d", &try2);
printf("if u entered below 5 then u won! !");
}
and this is the output I got:
function.c:22:5: note: declared here
int test(){
Solution 1:[1]
You declared your function again inside main. Remove int from infront of displayFlow.
#include <stdio.h>
int displayFlow();
int main(){
displayFlow();
}
int displayFlow(){
int try1,try2,try3;
printf("enter any given number...\n");
scanf("%d", &try1);
printf("if u entered above 10, ur out\n...please enter another guess...\n");
scanf("%d", &try2);
printf("if u entered below 5 then u won! !");
}
Solution 2:[2]
I come up with another mistake:you define the function displayFlow as 'int' type,but you don't write 'return' in the function when you realize it.
#include <stdio.h>
int displayFlow();
int main(){
displayFlow(); //you just abandon the return value?
}
int displayFlow(){
int try1,try2,try3;
printf("enter any given number...\n");
scanf("%d", &try1);
printf("if u entered above 10, ur out\n...please enter another guess...\n");
scanf("%d", &try2);
printf("if u entered below 5 then u won! !");
//Here is something absent. What do you want to return ? or you just want to return nothing? if so, you should modify the function return value type to 'void',please.
//return ??;
}
Solution 3:[3]
Just set return in method main, because he has to return int
int main() {
return displayFlow();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AaronSinn |
| Solution 2 | robotkkk |
| Solution 3 | Leonardo Alves Machado |
