循环不起作用,请提供任何答案,未使用某些变量..我知道,但它不会跳出循环
#include <stdio.h>
#include <stdlib.h>
int main(){
char name;
int Employees=0, idnum;
float Low=99999, High=0, earnings, Tearnings=0, Avgearnings;
while(name != "xxxx"){
if(earnings < Low)
{
Low = earnings;
}
if (earnings > High)
{
High = earnings;
}
printf("Enter name\n");
scanf("%s", &name);
printf("Enter earnings\n");
scanf("%f", &earnings);
Tearnings = Tearnings / earnings;
Employees = Employees ++;
}
Avgearnings = Tearnings / Employees;
printf("Average earnings: %2f", Avgearnings);
printf("Lowest Earnings: %2f", Low);
printf("Highest earnings: %2f", High);
return 0;
}
不会退出循环
最佳答案
您正在使用 while 循环,没有任何真正的中断条件。
您应该添加 if (xxx) {break}
或者将其更改为 var i;
for (i=0, i < earnings.length ; i++) { ... }
通过这样做,它应该让计划流程涵盖所有员工/收入,并在到达最后一个后继续。
关于c - 当字符串匹配时循环不会终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56294768/