0
나는 전화 기능을 배우려고 노력 중이며 a
, b
, c
및 d
을 선언해야한다고 들었지만 프로그램의 요점은 사용자에게 묻는 것입니다. 이 숫자들을 합한 다음 합계하십시오.변수를 입력하라는 메시지가 나타나면 어떻게 선언합니까?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int f(int a, int b, int c, int d);
int g(int b, int c, int d);
int h(int c, int d);
int i(int d);
int
main(int argc,char **argv)
{
int result;
result = f(a,b,c,d);
printf("Value of a?");
scanf("%d",a);
printf("Value of b?");
scanf("%d",b);
printf("Value of c?");
scanf("%d",c);
printf("Value of d?");
scanf("%d",d);
printf("Your result is %d",result);
return 0;
}
int
f(int a, int b, int c, int d)
{
return a + g(b,c,d);
}
int
g(int b, int c, int d)
{
return b + h(c,d);
}
int
h(int c, int d)
{
return c + i(d);
}
int
i(int d)
{
return d + d;
}
특정 경고
call.c:16:13: error: ‘a’ undeclared (first use in this function)
result = f(a,b,c,d);
이며 B, C 및 D에 대해 반복한다.
누구든지 내가 잘못한 것을 말할 수 있습니까? int a
, int b
, int c
및 int d
이 이미 정의 된 위치에 함수 서명을 넣었으므로 잘못 입력했는지 혼동합니다.
편집 : 질문이 해결되었습니다. 코드는 당신은,
int result, a, b, c, d;
는 또한 scanf
그것에 포인터 인수의 가변 부분의 기대
int result;
int a;
int b;
int c;
int d;
printf("Value of a?");
scanf("%d",&a);
printf("Value of b?");
scanf("%d",&b);
printf("Value of c?");
scanf("%d",&c);
printf("Value of d?");
scanf("%d",&d);
result = f(a,b,c,d);
printf("Your result is %d",result);
return 0;
'int result' 바로 다음에 선언하십시오. –
참고로 변수/함수 이름을 더 잘 설명하십시오. –
함수 f의 매개 변수는 main의 a, b, c, d와 관련이 없습니다. 당신은 그 (것)들을 w, x, y, z 또는 무엇이든이라고 부를 수 있었다. 그들은 main에서 선언되어야합니다. –