I am very new to programming, and have been following a C++ tutorial for the past week or so. Today, I decided to make my own console application without help to make sure I have all the concept down I have read so far. The application asks you in the beginning for 5 different words to put into a 5 element array. You are then prompted by a menu giving you 4 options: print the contents of the array, re-enter all the words again, edit only one array element, or exit the app.
When I choose the “edit only one array” option, the application gives another menu asking you to press “1” to print the array, or press any other key to just go on editing. The straight-to-editing option leads to a mashed up version of the start of the program, and using the “1” option leads to just chaos: https://i.stack.imgur.com/bFLLz.jpg. The console continues to print objects on the screen similar to the ones in the picture for about 5 seconds, until I am prompted by a popup asking me to end the process. I receive this in the output log after the application closes: pastebin.com/KcRU56Tg
The source code for my application can be found here: http://pastebin.com/vRUddYuK. I would normally attempt to debug this myself (and have been for the past hour and a half), but I feel that this is way over my head. Any help will be appreciated. Thank you.
do { ... } whilestatements should be avoided when doing iterations. It’s too easy to make logic errors like you did.Note that PrintInv is executing it’s cout statement when
n == 5, this is an error since inv only has valid elements for indices0...4.Rewrite your iterations with
and your logic will be clearer and bugs will be less likely to happen.