Hello, I'm trying to develop a program that returns the max, min, average and sum of a sequence. The problem is that I need to give the size of the sequence and it is messing it up. The program is working fine but it always asks for an extra number even though it applies the sum, average, min, max operations to the first three numbers.
I know it has something to do with the fact I'm asking for the first the input outside the loop and when my 'i' reachs three it still asks for one more number and then it breaks. I just can't sort it out!
You don't need an array or a vector for this. The calculations do not need the numbers stored in order to get the result.
As above, you need to initialize sum. soma doesn't even exist as a variable in your program.
Now for the answer to your question. What is i when you start the loop?
You should initialize your variables when you declare them. As is, they could be 5394757, and you wouldn't know until the program ran. The only reason things work out now is because your compiler caught your error of not initializing them, or (unlikely) the previous value in that address was 0. Good practice is to always initialize variables to a value in this language
I guess if it is working for you, then that's great, but you should have just incremented i after getting your first input. That would have worked without the break statement and extra check.
Yeah. You'll increment i outside of the while loop, so when you increment it after the last input, i will be equal to the size. The problem was that your i was equal to size-1 after the last input because it wasn't incremented after every input. If you increment it after the first input, i should be equal to size after the last input.