gpt4 book ai didi

c - 我的初学者 C 代码已停止工作

转载 作者:行者123 更新时间:2023-11-30 17:47:36 24 4
gpt4 key购买 nike

本学期我正在上第一堂编程课,但我不知道我的程序发生了什么。我必须编写一个程序来计算这么多年后的利息总额。公式为 y=p*(1+r)^n

无论如何,每当我运行代码时,它都会显示“_ 已停止工作”并关闭。

这是我的代码:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main (void)
{
double p, r, n, y;

printf("Enter the interest rate>");
scanf("%lf", r);
printf("Enter the principle amount of money invested>");
scanf("%lf", p);
printf("Enter the number of years invested>");
scanf("%lf", n);

y = pow(p*(1+r),n);

printf("The total amount of money is %f.\n", y);

system("PAUSE");
return (0);
}

我尝试用谷歌搜索它,看起来它可能与“初始化”有关,但我不确定这意味着什么或如何做。非常感谢任何帮助!

最佳答案

首先,scanf() 函数需要变量的地址而不是变量本身,因此应该像这样使用 scanf("%lf", &r);尝试一下,您就会发现会没事的

其次永远不要使用system("PAUSE")!!它是特定于平台的(Windows)并且是错误的system("pause"); - Why is it wrong?

您正在使用系统(暂停)以错误的方式学习编程,在上面的链接中您可以看到原因!

关于c - 我的初学者 C 代码已停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18889254/

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