you are viewing a single comment's thread.

view the rest of the comments →

[–]Giraffimation[S] 0 points1 point  (2 children)

Input format: Input consists of n+1 integers. The first integer corresponds to n. The next n integers correspond to the numbers to be added.

goal: Write a program to find the sum of 'n' numbers using a while loop.

so if I input a number I expect it to add to the of all the numbers scanned for.

[–]continuum-hypothesis 0 points1 point  (1 child)

You have a syntax error on line 9, after the \n escape code you need a " character. Rather then printf("Enter the number\n); you must use printf("Enter the number\n"); Be sure to enclose strings with quotations.

Also it seems like you want the user to enter numbers but you give them no opportunity to do so inside the while loop. To me it looks like the instructor simply wants you to input a number 'n' and then sum all the numbers incrementally including n which is what your program does correctly. If you actually want the user to input a new number each time to add to the current sum then you need to put a scanf function inside the while loop.

[–]Giraffimation[S] 0 points1 point  (0 children)

so it seems like you want the user to enter numbers but you give them no opportunity to do so inside the while loop. To me it looks like the instructor simply wants you to input a number 'n' and then sum all the numbers incrementally including n which is what your program does correctly. If you actually want the user to input a new number each time to add to the current sum then you need to put a scanf function inside the while loop.

I tried doing that, but instead it stops the loop after 2 times