[英]Error 1 error C2664: 'arl::contFolder *arl::list::setDown(arl::contFolder *,int *)' : cannot convert argument 2 from 'unsigned int' to 'int *'
[英]C error cannot convert argument 1 from int * to int
C和學習的新手。 我不斷收到錯誤消息(C2664:'int readScores(int,int,int)':無法將參數1從'int *'轉換為'int')。 我不知道如何解決它。 我嘗試查找它,但不理解錯誤代碼...我該如何解決? 同樣,代碼上的任何指針和/或提示也將不勝感激。 謝謝
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
// Functions
int readScores(int test1, int test2, int test3);
int determineGrade(int test1, int test2, int test3);
void print(int test1, int test2, int test3);
int main(void)
{
int test1;
int test2;
int test3;
readScores(&test1, &test2, &test3);
determineGrade(test1, test2, test3);
print(test1, test2, test3);
return 0;
}
void readScores(int *test1, int *test2, int *test3)
{
// Promts
printf("Hello, this program will determine");
printf("the grades of average test scores");
printf("to see if you passed or not this year.");
printf("Please enter in the three test...");
printf("Note: only enter scores that are (0-100)");
printf("Enter in test1\n");
scanf("%d", test1);
printf("Enter in test2\n");
scanf("%d", test2);
printf("Enter in test 3\n");
scanf("%d", test3);
return;
}
int determineGrade(int test1, int test2, int test3)
{
// Local declrations
int average;
// Math
average = 3 / (test1 + test2 + test3);
return average;
}
void print(int test1, int test2, int test3)
{
int Grade;
Grade = determineGrade(test1, test2, test3);
if (Grade > 90)
{
printf("Great job you have an A %d int the class\n", Grade);
return;
}
else if (70 < Grade > 90, test3)
{
if (test3 < 90)
{
printf("Good job you got a A %d\n", Grade);
return;
}
else
{
printf("Easy Beezy you got a B %d for the class\n", Grade);
return;
}
return;
}
else if (50 < Grade > 70, test2, test3)
{
Grade = 2 / (test2 + test3);
if (Grade > 70)
{
printf("You passed congrats you have a C %d for the class\n", Grade);
return;
}
else
{
printf("You have a D for the class %d\n", Grade);
return;
}
}
else if (Grade < 50)
{
printf("Yeah you might want to take this class again you have a F %d\n", Grade);
return;
}
return;
}
您必須制作函數原型,例如
int readScores(int test1, int test2, int test3);
匹配實際的函數實現:
void readScores(int *test1, int *test2, int *test3)
詳細說明一下。 程序中的數據流很好,您可以在main中聲明三個變量,並將這些變量的指針作為參數傳遞給readScores
,然后它們將對其進行修改。 然后將變量用於打印和計算。 因此,您唯一的問題是,在使用三個int指針實現編譯器時,首先錯誤地告訴編譯器“ readScores具有三個int參數”。
int readScores(int test1, int test2, int test3);
方法以int類型聲明,但是您可以使用指針定義(並調用)它。
將聲明更改為int readScores(int* test1, int* test2, int* test3);
在main
,沒有必要調用
determineGrade(test1, test2, test3);
就像您在打印功能中實際使用過的那樣。 另外, determineGrade
函數似乎有些偏離。 對於平均值,您希望等級的總和在分子中,而3的總和在分母中:
average = (test1 + test2 + test3) / 3;
盡管在從0到100取平均分數時不是必需的,但在將來取平均數時,最好取分子的每個部分並用分母分別除以然后加起來:
average = (test1 / 3) + (test2 / 3) + (test3 / 3);
如果分母項的總和可能大於MAX_INT
則可以避免溢出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.