First, let me congratulate you on nicely structured code. You have comments describing what you're doing, especially on the deleteItem() function.
There are a few problems with your code right now. First, the variable
input
in deleteItem is being treated as an index into the array, not a value in the array to delete. In other words, when you enter 200, it thinks you want to delete list[200], not "the value 200, wherever it occurs within the list."
Second, even if you enter an index instead of a value, the loop won't work:
for (int i = size; i < size -1; i++) {
First you assign i=size, then you check to see if i is less than size-1. That's false right from the start.
To delete the item at the index input. You have to start at input, and work your way up:
1 2 3
|
for (int i=input; i<size-1; ++i) {
list[i] = list[i+1];
}
|
Now, let's get back to those fine comments you write for deleteItem:
1 2
|
//delete an item (num) from the array
//if num is not found, will display 'Item Not Found'
|
Wait a sec. The comment says you're deleting num, but you prompt the user for some other number? What's up with that?
So you need three more changes (besides the one I mentioned):
1. Add code to find num within the array so you know which index to delete.
2. Modify the code to set input to the index where you found num.
Good luck, and again, nice job so far.