【发布时间】:2021-06-02 13:47:10
【问题描述】:
ATYB 银行在未来三年为 5 名学生提供大学奖学金
使用指针符号输入每个学生的各种奖学金金额
使用一个名为 totalschol 的模块,它有 2 个参数、一个数组和一个指向该数组的指针。
该模块输出(使用指针表示法)每个学生未来三年的总金额
#include <stdio.h>
#include <stdlib.h>
// Function Prototype..
void totSchol(float total [], float *aPointer);
int main(void)
{
// Declare Local Variables..
int i;
float amt[5]={0}, tot;
//points to the array variable.
float *aPointer = &amt[0];
//prompts AYTB Bank..
printf("\t\t AYTB Bank\n");
for (i=0; i<5; i++)
{
//prompts to enter scholarship amount for 5 students..
printf("Student %d, Enter scholarship amount: ", i+1);
//takes value entered and store in pointer variable aPointer & increment by i..
scanf("%f", aPointer + i);
tot += aPointer;
}
totSchol(amt, aPointer);
return 0;
}
void totSchol(float total [], float *aPointer)
{
int x;
float year3;
for (x=0; x < 5; x++)
{
printf("\nThe total amount for each studetn is: %.2f", (aPointer + x));
year = (aPointer +x) * 3;
printf("\nThe total amount for each studetn after 3 years is: %.2f", year3);
}
}
【问题讨论】:
-
哪一行导致错误?
-
tot += aPointer;
-
totSchol中aPointer + x的使用也不正确,你的意思是aPointer[x]
标签: c function function-pointers