C 简单的百分比传递程序不能正常运行
我的教授要求我们建立一个简单的程序,该程序接受分数,并显示通过的输入分数的百分比C 简单的百分比传递程序不能正常运行,c,C,我的教授要求我们建立一个简单的程序,该程序接受分数,并显示通过的输入分数的百分比 #include <stdio.h> #include <stdlib.h> int main() { int score=0; double percentPassing = 0, sum = 0, passing = 0; do { printf("Enter a test score (-1 to quit):");
#include <stdio.h>
#include <stdlib.h>
int main()
{
int score=0;
double percentPassing = 0, sum = 0, passing = 0;
do
{
printf("Enter a test score (-1 to quit):");
scanf("%i", &score);
if(score == -1){break;}
if (score > 100)
{
printf("That is not a valid grade!");
}
if(score >=0 || score <= 100)
{
sum = sum + 1;
}
if(score >= 70&&score <=100)
{
passing = passing + 1;
}
percentPassing = (passing/sum);
}
while (score != -1)
printf("\n Percent of grades that are passing: %.2d\n", percentPassing);
system("pause");
}
#包括
#包括
int main()
{
智力得分=0;
双百分比通过=0,总和=0,通过=0;
做
{
printf(“输入测试分数(-1)退出):”;
scanf(“%i”、&score);
如果(分数==-1){break;}
如果(分数>100)
{
printf(“这不是一个有效的分数!”);
}
如果(score>=0 | | score=70&&scoreif(score>=0 | | score)检查您的逻辑,您没有使用score来计算百分比。使用do-while,为什么您第一次要读取相同的输入两次?使变量小写。第一个条目(在循环外)未处理。输入-1增量Sum
。查看if/else if/else。检查scanf
的返回值。您不计算百分比(仅分数)如果没有*100
,百分传递
可以在循环外计算。您可能希望在printf
调用中使用空格/换行符。百分传递
是双精度的,但以浮点形式打印。您还需要检查if
语句的逻辑。
if(score >=0 || score <= 100)