Print items in structure with quantity < 10

Hi, i'm stuck trying to iterate through a structure, what im trying to do is print to a file items whose quantity is < 10.

My file looks like this:
1 apple 10
2 pineapple 5
3 banana 9
5 kiwi 6
6 pear 8

And my structure looks like
struct Inventory
  int id;
  string name;
  int quantity;

I know how to print the data to a new text file but i'm confused as to how only print those that have less than 10 items.
Last edited on
Hello Razgriz,

I know how to print the data to a new text file

So instead of printing to a file print to "cout". Inside the for loop use an if statement to print only those that are < 10.

If I had more to look at I could be more specific.

pseudo code:

for(all the items)
if (item.quantity < 10) //this is how it really looks in c++ or maybe if(array[index].quantity < 10)
file << << " " << << " " << item.quantity << endl;

the ones that are 10 or larger won't print, because of the condition.

Last edited on
Hi, i just noticed i didn't include more info sorry my bad.

I tried doing what Jonnin said before writing the original post and it only printed the first item on the file.

EDIT: I have managed to get it to work the way i was doing before, i don't know what i was doing wrong.
Last edited on
If you still have problems, post your code.
Registered users can post here. Sign in or register to post.