3
Would someone help me check which client is closest to the found media? When I compile from the 1.QNAN0 that is when I do a mathematical operation invalidates, I just don’t see which one 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);
}
The second
for (;i<f;i++)//ord
is never executed because the variablei
was assigned the value off
in the first cycle.– pmg