Can someone tell my why programs not working

What im trying to do is figure out a numbers multiples below 1000 and add them together. can someone tell me were i went wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
  using namespace std;
int m3;// first multiple//
int m1;
int i=0;
int main() { 

cout << "Please enter in your first number:";              
cin  >> m3;

while (10<i){// actual calculations//
int m2=i*m3;
  m1=m2+m1;
i++;
}
cout << m1;  

system("PAUSE");
      return 0;
}
Program never enters while loop since condition 10<0 is false at the beginning.

Also init m1 with 0 becouse it is jibberish at the beginning of program...
Last edited on
You went wrong a number of ways it seems:

1
2
int m3;// first multiple//
int m1;


Why is m3 labled "first multiple"? What is m1? "third mulitple"?


while (10 < i)

You declared i to be 0 here -> int i=0;

When is the constant 10 ever less than 0?

1
2
3
4
5
6
  while (10<i)
  {
    int m2=i*m3;
    m1=m2+m1;
    i++;
   }


Are your trying to find all muliples below 1000 or the number the user enters?


Last edited on
all of them and then adding them together. The first thing you pointed out i messed up there that was from my last attempt srry bout that.
So you're saying this is what you're trying to do? Find all multiples of x (an integer entered by user) that are below 1000. Then add the multiples together.
Last edited on
You are right but im just gonna re write the code because im pretty sure my math is way off thanks for the help though.
Last edited on
This is probably what you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        int num;
	int product;
	bool valid = true;
        vector<int> multiples;
	
	cout << "Enter a number;";
	cin >> num;
	
        for (int i = 0; i < 1000 && valid; i++)
	{
		product = num * i;
                if (product < 1000)	
                    multiples.push_back(product);
		else
                    valid = false; 	
	  }
	
Last edited on
Topic archived. No new replies allowed.