我正在嘗試制作一個演算法來找到學生成績的加權平均值(從 0 到 10),它有 4 個輸入:姓名、等級 1、等級 2、等級 3 在 vs 代碼中:
#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);
}
好吧,問題是當我運行時,它只執行到輸入第一個“鍵入你的一年級”行,然后它停止運行,就像它只是顯示程式所在的路徑一樣。我究竟做錯了什么?
uj5u.com熱心網友回復:
基本錯誤,總是在 scanf 中使用 & scanf("%f", &grade3);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/442970.html
下一篇:格式化結構中陣列中的字符
