Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom filter function does not produce expected output
    text
    copied!<p>I am trying to make a filter that prints on the screen only the data I want. Here's what I am talking about:</p> <pre><code>Cost* FilterSum(Controller* ctrl, int n) { int i; DynamicVector* CostList=getAll(ctrl-&gt;repo); for(i=0;i&lt;getLen(CostList);i++) { Cost* c=getElementAtPosition(CostList,i); //returns the element on one position if((c-&gt;sum)&lt;n) { return c; //if the element(Cost in my case) has the sum&lt;20 return it } } return 0; } </code></pre> <p>So, I have Dynamic Array with Costs as elements. If the sum of the cost is less than n(n is given from the keyboard) I want to print on the screen only those costs. :) This are the print functions in the console:</p> <pre><code>void PrintCost(Cost* c) //this function prints one cost { printf("\nID: %d\n", getID(c)); printf("Day: %s\n", getDay(c)); printf("Type: %s\n", getType(c)); printf("Sum: %d\n\n", getSum(c)); } void PrintCosts(Console* console) //this one prints all the costs in the list { DynamicVector* CostList=getAllCosts(console-&gt;ctrl); if (getLen(CostList)) { int i; for(i=0;i&lt;getLen(CostList);i++) { Cost *c=(Cost*)getElementAtPosition(CostList,i); PrintCost(c); } } else printf("No cost in the list!"); } </code></pre> <p>And here is the call function from controller in the console:</p> <pre><code>void FilterCostsBySum(Console* console) { int n; printf("See the costs that have the sum less than: "); scanf("%d",&amp;n); Cost* c = FilterSum(console-&gt;ctrl,n); PrintCost(c); } </code></pre> <p>Now, here comes the problem. If I have Monday with sum=10, Friday with sum=20 and Saturday with sum=40 and I want to print only those days with sum&lt;30, it just prints Monday and that's it, it doesn't print Friday too. Where am I doing wrong? In the FilterSum function in the controller where I return the c? I tried everything and it didn't work at all... maybe you can help me! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload