Hello,

I have a data structure which consists of 3 numbers. The data is later on saved in an array each time the user enters a new "izdelek".

struct izdelek
{
    double st_izdelka;
    double teza;
    double cena;
};

later on, i have a function which should compare the cena numbers of all elements in the array and find the smallest and return (by reference) the array index in which the smallest cena is.

void min_cena(izdelek seznam_izdelkov[],int i,int& indeks2)
{
    int j;
    int min=seznam_izdelkov[0].cena;
    for(j=0; j<i; j++)
    {
	   if(seznam_izdelkov[j].cena<min)
	   {
          min=seznam_izdelkov[j].cena;
		  indeks2=j;
	   }
    }
}

it never gives the right index. I simply dont understand what's wrong, since another function i have(which returns the index of the highest "teza") is almost the same and it works:

void najteza(izdelek seznam_izdelkov[],int i,int& indeks)
{
    int j;
    int max=0;
    for(j=0; j<i; j++)
    {
	   if(seznam_izdelkov[j].teza>max)
	   {
          max=seznam_izdelkov[j].teza;
		  indeks=j;
	   }
    }
}

So what's wrong with void min_cena? Any help would be much appriciated.

Nevermind, i found out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.