[英]Conflicting Types for Function?
我有一個程序可以在結構數組中接收有關5個學生的信息,然后使用該信息進行計算以確定學費。 目前,我不知所措,無法解決這些錯誤。 例如,它說
#include <stdio.h>
#include <stdlib.h>
#define UnitCost 100
#define MAX 60
int calculator(int x, char y);
void getInput(struct student* memb);
void printOutput(struct student * memb);
typedef struct student{
char name[MAX];
char housing;
int total;
int units;
} student;
int main()
{
struct student user[5];
int total[5] = {0,0,0,0,0};
int loopControl;
int i;
char name[5][MAX];
int units;
char housing;
for (loopControl = 0; loopControl <= 4; loopControl++){
getInput(&user);
total[loopControl] = calculator(units, housing);
}
for(i = 0; i < 5; i++){
printf("\nStudent Name: %s", user[i].name);
printf("\nAmount due: $%d\n", user[i].total);
}
printf("\nAverage: %d\n", (total[0] + total[1] + total[2] + total[3] + total[4])/5);
return 0;
}
// -----------------------------------------------------------------------------
int calculator(int x, char y){
int onCampusCost = 0;
int unitCostTotal = 0;
int unitsEnrolledDiscount = 0;
if (x > 12){
unitsEnrolledDiscount = (x - 12) * 10;
}
if (y == 'n'){
onCampusCost = 0;
}
else if (y == 'y'){
(onCampusCost = 1000);
}
if (x >12){
unitCostTotal = (x * 100) - ((x - 12) * 10);
}
else{
unitCostTotal = x * 100;
}
return onCampusCost + unitCostTotal;
}
void printOutput(struct student * memb){
}
void getInput(struct student* memb){
char name[5][MAX];
char house;
int uns;
printf("Enter student name: ");
if (iter > 0) getchar();
gets(name);
memb->name = name;
printf("Do you live on campus?\ny/n: ");
scanf("%c", house);
memb->housing = house;
printf("How many units are you enrolled in?: ");
scanf("%d", uns);
memb->units = uns;
}
錯誤:
|| ===構建:在f中調試(編譯器:GNU GCC編譯器)=== | 警告:“結構學生”在參數列表中聲明| 警告:“結構學生”在參數列表中聲明|
|在函數“ main”中:|
警告:從不兼容的指針類型傳遞'getInput'的參數1
注意:預期為“結構學生”,但參數的類型為“結構學生( )[5]” |
警告:未使用的變量“名稱” [-Wunused-variable] |
在函數“計算器”中:| 警告:設置了變量'unitsEnrolledDiscount'但未使用[-Wunused-but-set-variable] |
錯誤:“ printOutput”的類型沖突
注意:'printOutput'的先前聲明在此處|
錯誤:“ getInput”的類型沖突|
注意:“ getInput”的先前聲明在此處|
在函數“ getInput”中:|
錯誤:未聲明“ iter”(此函數中的首次使用)|
注意:對於每個未聲明的標識符,對於每個出現在||中的函數,只報告一次。
警告:從不兼容的指針類型|中傳遞'gets'參數1
注意:預期為'char ',但參數的類型為'char( )[60]'|
錯誤:分配給具有數組類型|的表達式
警告:格式'%c'期望的參數類型為'char *',但參數2的類型為'int'[-Wformat =] |
警告:格式'%d'期望參數類型為'int *',但是參數2的類型類型為'int'[-Wformat =] | || ===構建失敗:4個錯誤,9個警告(0分鍾,0秒)=== |
請請幫助
@Lumii問題出在您的代碼中:-
指導學生
int計算器(int x,char y);
無效的getInput(結構學生*成員);
無效的printOutput(結構學生*成員);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.