[問題] C語言的練習題一問
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
寫一程式預測某一科學為達所希望的成績時,期末考的成績。
希望得到的正確結果:
Enter desired grade>B
Enter minimum average required> 79.5
Enter current average in course> 74.6
Enter how much the final counts
As a percentage of the course grade> 25
You need a score of 94.20 on the final to get a B
程式跑出來的錯誤結果:
只有下面一行算出來的值是錯的。(前面的條件一樣)
You need a score of 83.434319 on the final to get a B
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
DEV-C++
有問題的code: (請善用置底文標色功能)
我猜想是下面2行
float result=(B_value-average*0.75)/(value/100);
printf("You need a score of %f the final to get a %c",result,B);
補充說明:
補上完整的程式碼:
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main(int argc, char *argv[])
{
char B;
float B_value,value,average;
printf("Enter desired grade=>");
scanf("%c",&B);//.Reading characters with scanf()
printf("Enter minimum average required=>");
scanf("%f",&B_value);
printf("Enter current average in course=>");
scanf("%f",&value);
printf("Enter how much the final counts As a percentage of the course
grade>");
scanf("%f",&average);
float result=(B_value-average*0.75)/(value/100);
printf("You need a score of %f the final to get a %c",result,B);
system("PAUSE");
return 0;
}
最後附帶一提:我用VC++有寫出來!可是用C來寫,值卻錯了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.2.178
推
07/18 10:42, , 1F
07/18 10:42, 1F
→
07/18 10:44, , 2F
07/18 10:44, 2F
→
07/18 10:46, , 3F
07/18 10:46, 3F