gpt4 book ai didi

c - 我认为我没有正确使用指针。 C

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:57 25 4
gpt4 key购买 nike

所以我已经尝试做这个作业几个小时了,但我无法弄清楚,我 99% 确定这与我使用指针的方式有关。我得到的错误是中断 0xC0000005:访问冲突写入位置 0xCCCCCCCC。我认为这意味着我的一些指针为空。提前为业余代码道歉..

#include<stdio.h>

void load(int *salary)
{
printf("Please enter your salary: ");
scanf("%d", *salary);
}

void calc(int *salary, float *rate, int *raise, int *newsalary)
{
rateofsalary(&salary);
*raise = *salary/(*rate);
*newsalary = *raise+*salary;
}
float rateofsalary(int *salary)
{
float rate;
if(*salary<0 && *salary>=30000)
rate = 7.0;
else
if(*salary<30000 && *salary>=40000)
rate = 5.5;
else
if(*salary<40000)
rate = 4.0;
return rate;
}

void print(int *salary, float *rate, int *raise, int *newsalary)
{
printf("| | Salary | Rate % | Raise | New Salary |\n");
printf("| | %d | %0.2f | %d | %d |\n", salary, rate, raise, newsalary);
}

void main()
{
int salary, raise, newsalary;
float rate;
load(&salary);
rateofsalary(&salary);
calc(&salary, &rate, &raise, &newsalary);
print(&salary, &rate, &raise, &newsalary);
}

最佳答案

scanf("%d", *salary);

改成

scanf("%d", salary);

printf 函数应该是

printf("|     | %d     | %0.2f  | %d    | %d         |\n", *salary, *rate, *raise, *newsalary);

关于c - 我认为我没有正确使用指针。 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19339516/

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