所以我已经尝试了几个小时来完成这项任务,但我无法弄清楚,我 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);
}