Hello seghrein2300,
If I understand your desired output correctly you are trying to sort each input after you enter it. This will not work because as you enter into the array you start at element (0) zero and work up. Sorting the array before all the entries are complete would mean that you will overwrite elements 3, 4 and 5 and your final output will not be what you want. Your do/while loop does not work because it is an endless loop with no way out. Look at what seeplus has done to eliminate the do/while loop. This is better. His code is a good start, but still could be etweeked a bit. The "display" function is a good idea, but I do not know if you are ready for that yet. With a little work you could take the contents of the function and put that in "main". Putting the sort inside the for loop I get this:
----------------------------------------------
Product # Name
0 -NONE-
1 -NONE-
2 -NONE-
3 -NONE-
4 -NONE-
----------------------------------------------
Enter Product name: shoes
----------------------------------------------
Product # Name
0 -NONE-
1 -NONE-
2 -NONE-
3 -NONE-
4 shoes
----------------------------------------------
Enter Product name: pants
----------------------------------------------
Product # Name
0 -NONE-
1 -NONE-
2 -NONE-
3 pants
4 shoes
----------------------------------------------
Enter Product name: glove
----------------------------------------------
Product # Name
0 -NONE-
1 -NONE-
2 glove
3 pants
4 shoes
----------------------------------------------
Enter Product name: tie
----------------------------------------------
Product # Name
0 -NONE-
1 -NONE-
2 glove
3 shoes
4 tie
----------------------------------------------
Enter Product name: hat
0 -NONE-
1 -NONE-
2 glove
3 hat
4 shoes
// This would be the sorted output.
0 -NONE-
1 -NONE-
2 glove
3 hat
4 shoes
Notice after the 3rd entry you are overwriting the last variables in the array until the for loop ends. The better choice here is to fill the array then sort it.
Hey guys, sorry my internet cut out. I have these in me. But after filling the "0,1,2,3,4" If I try to enter another one instead of replacing what is in 4. it changes what is in 3.
-------------------------------
Product # Name
0 PANTS
1 SHIRT
2 HAT
3 SOCKS
4 SHOES
-------------------------------
Enter product name: MONEY
-------------------------------
Product # Name
0 PANTS
1 SHIRT
2 HAT
3 MONEY <-------- THIS IS WHERE IT REPLACES INSTEAD OF
4 SHOES <---------- HERE.
-------------------------------
Enter product name:
@seeplus, yes exactly like that but is there a way to loop it?
Thank you, @seeplus.
I'll try to work for now with the code that I recently added, I'm just trying to fix the overwriting in the # 3 instead of #4 if STRINGS is full, I still haven't figured out a good solution yet.
If arr is full, I want to overwrite what is written on Product # 4, like.
-------------------------------
Product # Name
0 PANTS
1 SHIRT
2 HAT
3 SOCKS
4 SHOES
-------------------------------
Enter product name: APPLE
-------------------------------
Product # Name
0 SHIRT
1 HAT
2 SOCKS
3 SHOES
4 APPLE
-------------------------------
Enter product name:
Thank you so much, seeplus. That's a very big help. I will be studying the codes you just posted to get me a better explanation.
I will just change the first top program because it's not a connected program.
I will change it to like, the items/products is displayed already. fruits[5] = {Apple, Grapes, Lemon, Mango, Peach}; if that is possible? like:
Item name(s)
[0] = Apple
[1] = Grapes
[2] = Lemon
[3] = Mango
[4] = Peach
Enter item to search: