0

loop not working, any answers please, some variables are not used ..i know, but it will not get out of the loop

#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;   
}

it will not exit the loop

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

0

You are using a while loop without any real break condition.

You should either add a if (xxx) {break} or change it to var i; for (i=0, i < earnings.length ; i++) { ... } by doing this, it should have the program process through all of your employees/earnings, and move on after it gets to the last one.

jmdatasci
  • 111
  • 9