Problem with simple program

Hi, I want to make a program which inputs two integers N and d and outputs all integers between 1 and N, which are divisable by d!

And i think i did it but there is an error.May be the entire code is completely wrong, but here it is:


#include <iostream>
#include <cmath>
using namespace std;


int main()
{
int N;
int d;
int i=0;
cout << "Please enter two integers";
cin >>N>>d;



while (i=N)
i++;
{
if (i % d ==0)
cout << i;
}



system ("PAUSE");
return 0;
}



Can u tell me where is the mistake?
Last edited on
1
2
3
4
5
6
while (i=N)
i++;
{
if (i % d ==0)
cout << i;
}

i=N is assignment. you meant ==.
now only i++ is in the while loop.
even without these problems it won't do what you want. you want a for loop (that is
1
2
3
for(i = 1; condition_for_the_loop_to_continue; i++){
   //what you wrote
} 
)
while (i=N) means N is now assigned to i. It should be i==N, but still that wouldn't be correct.

It would make more sense to use a for loop for this.

1
2
3
4
5
6
for ( int i = 1; i <= N; i++ )
{
     if ( i % d == 0 )
        cout << i << endl;
}
Thanks a lot.Omg what stupid mistake (i=n,i==n).I didnt saw it.Thank u guys.. :)
Topic archived. No new replies allowed.