gpt4 book ai didi

c - 我的简单代码没有给出输出

转载 作者:行者123 更新时间:2023-11-30 18:30:39 26 4
gpt4 key购买 nike

#include <stdio.h>
#include <conio.h>
int main(void)
{
int year;
float principal, amount, inrate, period, value;
printf ("Please enter principal");
scanf ("%f", principal);
amount = principal;
printf ("Please enter interest rate");
scanf ("%f", inrate);
year = 0;
printf ("Please enter period");
scanf ("%f", period);
while(year <= period)
{printf ("%d %f\n", year, amount);
value = amount + amount*inrate;
year = year + 1;
amount = value;
}
getch();
return 0;
}

我尝试运行此代码,但根本没有输出。有 0 条警告和消息。坦率地说,我不知道代码是否能够达到预期目的而无法运行它!请帮忙。

最佳答案

I tried running this code but I have no output at all

真的吗?我收到了 6 条警告和一个段错误!你使用什么编译器?

        ||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
main.cpp||In function 'int main()':|
main.cpp|8|warning: format '%f' expects argument of type 'float*', but argument 2 has type 'double' [-Wformat]|
main.cpp|11|warning: format '%f' expects argument of type 'float*', but argument 2 has type 'double' [-Wformat]|
main.cpp|14|warning: format '%f' expects argument of type 'float*', but argument 2 has type 'double' [-Wformat]|
main.cpp|8|warning: 'principal' is used uninitialized in this function [-Wuninitialized]|
main.cpp|11|warning: 'inrate' is used uninitialized in this function [-Wuninitialized]|
main.cpp|14|warning: 'period' is used uninitialized in this function [-Wuninitialized]|
||=== Build finished: 0 error(s), 6 warning(s) (0 minute(s), 0 second(s)) ===|

代码看起来像某种利息计算器 ( https://en.wikipedia.org/wiki/Interest )

尝试该代码:

    #include <stdio.h>
#include <conio.h>
int main(void)
{
int year;
float principal, amount, inrate, period, value;
printf ("Please enter principal ");
scanf ("%f", &principal);
amount = principal;
printf ("Please enter interest rate ");
scanf ("%f", &inrate);
year = 0;
printf ("Please enter period ");
scanf ("%f", &period);
while(year <= period)
{
printf ("%d %f\n", year, amount);
value = amount + amount*inrate;
year = year + 1;
amount = value;
}
getch();
return 0;
}

关于c - 我的简单代码没有给出输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com