2014-03-01 50 views
1

新的C和学习。我不断收到错误(C2664:'int readScores(int,int,int)':无法将参数1从'int *'转换为'int')。我不知道如何解决这个问题。我尝试过查找它,但不明白错误代码... 我该如何解决它? 任何指针和/或代码的提示将不胜感激。 感谢C错误不能将参数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; 
} 
+0

您的'readScores'声明与'readScores'的定义不符。参数类型不同。即使是返回类型也不同。这没有意义。你想通过做出不匹配的定义来做什么?你是代码的作者吗? – AnT

回答

0

int readScores(int test1, int test2, int test3);方法声明为int类型,但是你定义(和调用),它的指针。

变更申报为int readScores(int* test1, int* test2, int* test3);

+0

更改scanf调用是错误的 - 它需要一个地址,而不是int。 –

+0

@JimBalter我不好,谢谢你指出。 –

2

您必须进行函数原型,例如

int readScores(int test1, int test2, int test3); 

符合实际的功能实现:

void readScores(int *test1, int *test2, int *test3) 

要详细一点。程序中的数据流很好,你在main中声明了三个变量,并将那些指针作为参数传递给readScores,然后它们将修改它们。这些变量然后用于打印和计算。所以你唯一的问题是,当你用三个int指针实现它时,你首先错误地告诉编译器“readScores有三个int参数”。

0

main,没有必要调用

determineGrade(test1, test2, test3); 

,你叫真正把它用在你的打印功能。此外,determineGrade函数似乎有点关闭。对于一般的,你想要的成绩的总和是在分子和3是在分母:从0-100采取评分的平均值时,在服用时平均

average = (test1 + test2 + test3)/3; 

虽然不是必需的未来,这将是很好走分子的各个部分和分母分别除以它们,然后将它们添加:

average = (test1/3) + (test2/3) + (test3/3); 

这避免溢出,如果你的分母项可以总结为大于MAX_INT

相关问题