I need to figure out how to write a program that prints the answer to
5+10+15+...2000
#include <iostream>
using namespace std;
int main()
{
int num;
int limit = 2000;
cout << "number" << endl;
cin >> num;
while ( num <= limit )
{
int increase = 5;
num = num + increase;
cin >> num;
}
cout << "The answer is " << num << endl;
return 0;
}
what am I doing wrong? I must be forgetting a step.
@musicislife2398
Since you already know the values you're adding up, what is the cin >> num for? Just set num to zero. Limit is already set. Put the int increase =5 with the other ints. Change the while loop to a for loop, and increase by 5 with the limit: for ( int x=5;x<=limit;x=x+5) Have increase = increase+x and the next line to be num=num+increase You can't use an int, though, for num. The answer is going to be a VERY, VERY LARGE number. Good luck!!
*** EDIT *** I was mistaken, you can use int for num. I was getting an error upon compiling, but it was because I forgot to initialize num to zero.