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

时间:2019-05-24 14:34:10

标签: 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;   
}

它不会退出循环

1 个答案:

答案 0 :(得分:0)

您正在使用while循环,而没有任何实际中断条件。

您应该添加一个if (xxx) {break}或将其更改为var i; for (i=0, i < earnings.length ; i++) { ... },它应该使所有员工/收入都经过计划处理,然后再转到最后一个。