我的代码运行没有错误,但它只运行了一段代码(C语言)
My code runs with no errors but it runs only a section of the code (C Language)
我正在尝试制作一种算法来查找学生成绩(从 0 到 10)的加权平均值,该算法在 vs 代码中获得 4 个输入:姓名、成绩 1、成绩 2、成绩 3:
#include <stdio.h>
int main()
{
float grade1, grade2, grade3, weightedaverage;
char studentname[50];
printf("\nType the name of the student: ");
fgets(studentname, 50, stdin);
printf("\nType the first grade: ");
scanf("%f", grade1);
printf("\nType the second grade: ");
scanf("%f", grade2);
printf("\nType the third grade: ");
scanf("%f", grade3);
weightedaverage = (grade1 *2) + (grade2 *4) + (grade3 *6) / 12;
//
printf("\nNAME: %s\nWEIGHTED AVERAGE: %f", studentname, weightedaverage);
return(0);
}
嗯,问题是当我 运行 时,它只执行到第一个“输入你的一年级”行的输入,然后它停止 运行ning,就像它显示的那样之后是程序所在的路径。我做错了什么?
基本错误,始终在 scanf 中使用 & scanf("%f", &grade3);
我正在尝试制作一种算法来查找学生成绩(从 0 到 10)的加权平均值,该算法在 vs 代码中获得 4 个输入:姓名、成绩 1、成绩 2、成绩 3:
#include <stdio.h>
int main()
{
float grade1, grade2, grade3, weightedaverage;
char studentname[50];
printf("\nType the name of the student: ");
fgets(studentname, 50, stdin);
printf("\nType the first grade: ");
scanf("%f", grade1);
printf("\nType the second grade: ");
scanf("%f", grade2);
printf("\nType the third grade: ");
scanf("%f", grade3);
weightedaverage = (grade1 *2) + (grade2 *4) + (grade3 *6) / 12;
//
printf("\nNAME: %s\nWEIGHTED AVERAGE: %f", studentname, weightedaverage);
return(0);
}
嗯,问题是当我 运行 时,它只执行到第一个“输入你的一年级”行的输入,然后它停止 运行ning,就像它显示的那样之后是程序所在的路径。我做错了什么?
基本错误,始终在 scanf 中使用 & scanf("%f", &grade3);