C 错误无法将参数 1 从 int * 转换为 int

标签 c if-statement for-loop 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;
}

最佳答案

你必须制作函数原型(prototype),例如

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

匹配实际的功能实现:

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

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

关于C 错误无法将参数 1 从 int * 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109601/

相关文章:

c - 如何指示窗口过程中处理消息时出现的错误?

c - setjmp.h 在内核空间中?

c - 减少arduino的代码,通用代码

python - 如何在 pandas dataframe (Python) 中将单元格的新值设置为 float - 在嵌套 for 循环中时,DataFrame 将舍入为整数

python - 如何为非常相似的代码片段编写方法或 for 循环

javascript - 如何在javascript中正确获取json数据

c - 声明动态多维指针

c - 在 waf 中,如何定义对来自另一个子目录的生成 header 的依赖

javascript - "else if"Javascript计算器中的条件

Java 抛出 NoSuchElementException