Why do I get QNAN Error when I calculate this?

Question:

Can someone help me check which client is closest to the average found? When I compile from 1.QNAN0 which is when I do an invalid math operation, I just don't see what it is :/ header file to compile

#include <stdio.h>
#include "exercicios.h"
#include <strings.h>

struct cliente reg [50];
float media(int , int);
void cria_cli(int i, int f){
for (;i<f;i++)
{
    reg[i].codigo=i+1;
    reg[i].potencia=potencia[i];
    strcpy(reg[i].nome,clientes[i]);
    reg[i].preco=preco[i];
    reg[i].status='*';

   }
 }
void lista_cli(int i, int f){
for (;i<f;i++)
{
    printf("%d - %-20s \n", reg[i].codigo, reg[i].nome);
}
    printf("media - %f ",media(0,50));
}

   float media(int i, int f){
   float dif=1.0, p;
   float media;
   float m=0;
       for (;i<f;i++)
{
    m+=  (reg [i].potencia * reg[i].preco);

}
   media = m/f;
  for (;i<f;i++)//ord
        if(media-(reg[i].potencia * reg[i].preco)<dif){
            dif = media - (reg[i].potencia * reg[i].preco);
                  p   = reg[i].potencia * reg[i].preco;

  }
}


int main(){

cria_cli(0,50);
lista_cli(0,50);

}

Answer:

The media() function does not have a return statement!

Scroll to Top