c - 当字符串匹配时循环不会终止

标签 c

循环不起作用,请提供任何答案,未使用某些变量..我知道,但它不会跳出循环

#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/

相关文章:

c - Linux 内核的这个源代码有什么作用?

c - 使用 Lua 注册一个闭包

c++ - 指针到指针、指向值地址和二维数组访问之间的清晰度

C 程序抛出运行时错误

使用带结构的 C 创建地址簿

c - fwrite问题,无法写入二进制文件!

c - fork系统调用导致段错误

c - 如何增加字符串表中的指针?

c - 检查所有 int 数组元素是否等于特定数字的最短代码?

c++ - 为什么我们在从 main() 返回时遵循相反的约定?