> C++ Programming Help. I was given the task to write a program for homework. Write a program that asks the user for a pos

C++ Programming Help. I was given the task to write a program for homework. Write a program that asks the user for a pos

Posted at: 2014-12-18 
You're adding the wrong number to "sum". You should be adding "sum + x" because it's your "x" value that's changing.

So, start your loop counter at '1' (no use adding zero to your sum), and end it with "x=num".

You also should consider using your "IF (num > 0)" statement to protect your loop. You want to do *as little* processing as possible if num isn't greater than zero.

Example:

Start of Pgm...

--Ask user for 'positive' number

--If number is positive:

---- Loop from 1 by 1 until index = "number entered"

---- Add loop index to SUM each time

---- When loop ends, print the SUM

--Else (number isn't positive)

---- tell user they've been naughty

--End of IF

End of Pgm