Hey guys. Good evening.
So i've been trying to do a line of code for about a hour now but I don't seem to get it.
3 <-- how many lines
1 12.50 2
3 10.50 1
2 7.50 3
^...^...^
r ...s... k
I need to find the lowest sum of the list shown above.The anwswer is 3 10.50 1
The first one means the type of flower it is. The second one is the flowers price
The last one is how many of the flowers are there.
The exercise asks me to get the lowest sum of the diffrent types of flowers. Which is 3 10.50 1.
I've tried this and many more things. ( ind = indicator of what type of flower)
if ( lowest > s1) // s1 = s * k;
{
lowest =s1;
ind1 = s1;
ind1 = i;
I would appreciate some help. I just need this to be explained
for all the entries
find the smallest of 2nd*3rd
looks like you are close...
something like (not real code)
double lowest = first_2times3;
for( i = second; i < total_lines; i++)
{
tmp = this_entry2ndtimes3rd;
if(tmp < lowest)
save i or tmp or both whatever you needed.
}
When posting code, please use code tags so that the code is readable:
[code]
code goes here
[/code]
1 2 3 4 5
if ( lowest > s1) // s1 = s * k;
{
lowest =s1;
ind1 = s1;
ind1 = i;
Both L4 and L5 set ind1 - with L5 overwriting the value set in L4.
What is lowest initialised to? Often in these situations it's set to be larger than the possible value - or to the largest possible for its type. If lowest is already set to a value lower than the found lowest, then the if condition will never be true!