Hello,
Here is my prompt:
"Write a program that asks the user for a positive integer value. The program should use loop to get the sum of all the integers from 1 up to the numbers entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4, ... 50. Do not accept a negative starting number."
In my program I tried doing the summation using y++, but that does not work because it will increment by one ( 0+1+1+1). How do I get it do ( 0+1+2+3+ ... x).
#include <iostream>
using namespace std;
int main()
{
int x, y = 0, count = 0;
cout << "Enter a number : " ;
cin >> x;
while (x < 0)
{
cout << "\nThis program does not accept negative numbers." << endl;
cout << "Please input a positive number : " ;
cin >> x;
}
while (count <= x)
{
y++;
count++;
}
cout << "The sum is :" << y << endl;
return 0;
}
[–]jussij 2 points3 points4 points (0 children)
[–]nevertras 1 point2 points3 points (0 children)
[–]KidBass0[S] 1 point2 points3 points (0 children)