C++ beginner - Sum of multiples less than 100
Hey guys, this is my first post here. I am a beginner in C++ and have a question for a homework assignment. I have read my book over and over and can't seem to figure out how to code this properly.
What I want it to do is have the user input a number: ex. 5 and then have the code give the sum for all the multiples of 5 less than 100, so it should be equal to 950 in this example.
Anyway, I have got so far to get it to list the numbers, but I need the sum of those numbers without all the text displayed every time.
I have chosen to use the FOR, but I am wondering if I should implement WHILE loop in my coding somewhere. I just don't know how to go about it for this problem.
Again, this is my first post (and definitely not my last!) I hope I have read the rules properly. It is my first programming class in school, and I am seeing a tutor tomorrow and the next day, I would just like to have a better grasp of this before going in tomorrow.
Code:
#include <iostream>
using namespace std;
int addMultiples()
{
// Start
cout << "What multiples are we adding? ";
int start;
cin >> start;
int increment = start;
for (int count = start; count <= 100; count += increment)
cout << "The sum of multiples of " << start
<< " less than 100 are: " << count << endl;
return 0;
}
int main()
{
addMultiples();
return 0;
}
I want the output like this:
What multiples are we adding? 5
The sum of the multiples of 5 less than 100 are: 950
Thanks for your help and explanations!