ARTICLE AD BOX
Good evening!
I am new to programming and I am learning C++ and I have an assignment that I need a little help, if anyone can guide me through it.
The assignment is: Assume an int variable named maxValue has been defined and assigned a value greater than 0. Also assume an int variable named sum has been defined but has not been assigned a value.
Write a code snippet that uses a loop to calculate the sum of all the integers from 1 through maxValue (inclusive). Store the sum in the sum variable.
I have tried a few different methods but I cannot get the results it is asking for, however the code is compiling without an issue.
This is the code that has gotten me the closest results and I am not sure what is wrong, if someone could give me a hint, I would appreciate it!
sum = 0; for (int count = 1; count <= maxValue; count++) { sum = count + maxValue; }