[英]Function not giving normal output
我正在嘗試編譯我的函數練習。 我嘗試了很多次編譯這個,但我遇到了這個問題。
下面是我的代碼:
#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! !");
}
這是我得到的 output:
function.c:22:5: note: declared here
int test(){
您在 main 中再次聲明了您的 function。 從 displayFlow 的前面刪除 int。
#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! !");
}
我又犯了一個錯誤:你把function的displayFlow定義為'int'類型,但是你意識到function時沒有寫'return'。
#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 ??;
}
方法main里面設置return就行了,因為他要return int
int main() {
return displayFlow();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.