0

我似乎无法解决这个问题。我对另一个程序有相同的设置,它是一个堆栈、推送/弹出,它工作得很好。我第一次收到函数错误中使用的未声明值。任何帮助,将不胜感激。

头文件

#include <stdio.h>
#include <string.h>

int money();
void amortization();

typedef struct{
int principle;
int rate;
int payments;
} loan_t;

功能码

int money(loan_t)
{
 printf("Please input the amount borrowed:");
 scanf("%d", &principle);
 printf("\nPlease input the Annual Interest Rate:");
 scanf("%d", &rate);
 printf("\nPlease input the number of monthly payments:\n");
 scanf("%d", &payments);
 return (principle,rate,payments);
 }

谢谢你!

4

2 回答 2

1

尝试:

 int money(LOAN *var){
     printf("Please input the amount borrowed:");
     scanf("%lf", var->principle);
     printf("\nPlease input the Annual Interest Rate:");
     scanf("%lf", var->rate);
     printf("\nPlease input the number of monthly payments:\n");
     scanf("%lf", var->payments);
     return 0;
 }

将标题更改为:

#include <stdio.h>
#include <string.h>

typedef struct loan{
    double principle;
    double rate;
    double payments;
}LOAN;

int money(LOAN *var);
void amortization();

这意味着您将返回loan_t带有所需值的 a

编辑:编辑以最适合您,而不是 Jonathan Leffler 推荐的最佳实践

声明一个LOAN variable;内部main()然后调用money(&variable);

于 2013-05-07T00:10:42.463 回答
0

根据您提供的内容,它看起来像principle, rate,并且payments都未在money. 您还提供了一个类型作为参数,而money.

编辑:正如其他回答者所指出的,回报也很可疑。

我现在无法自己测试,但请尝试:

loan_t money(loan_t loan)
{
 printf("Please input the amount borrowed:");
 scanf("%lf", &(loan.principle));
 printf("\nPlease input the Annual Interest Rate:");
 scanf("%lf", &(loan.rate));
 printf("\nPlease input the number of monthly payments:\n");
 scanf("%lf", &(loan.payments));
 return loan;
 }
于 2013-05-07T00:08:35.350 回答