Originally Posted by

**KCfromNC**
if (index != 0) // if we didnt increment index during that operation

Comment doesn't match the code here.

hmm, thats cuz i messed w/ it a lot before finally posting here.

i still have the problem tho, i tried lowering my range to 100 and i get 3-10 as prime numbers, when clearly numbers like 4, and 6 are not, and 1-3 nothing shows. im still confused.

here is what i have, yet again.

Code:

/*variables needed num1, num2, index.
if num1 % num2 = 0 index++, if index = 0 print num1. */
#include <iostream>
using namespace std;
int main ()
{
int num1, num2;// the 2 numbers we divide to find the remainder
int remainder=0, index=0; // remainder determines if the number is prime or not
for(num1=1; num1 <= 10; num1++) // we take each number under 100
{
cout << "after first for loop num1 is " << num1 <<endl;
cout << "after first for loop index is " << index <<endl;
index = 0;// we reset index back to 0
for(num2=1; num2<num1; num2++) //and mod it be each number lower than itself
{
remainder = num1%num2; // find out the remainder of it
cout << "after second for loop num2 is " << num2 << endl;
cout << "after second for loop remainder is: " << remainder << endl;
if(remainder == 0) // and if there is none
{
++index; // we increment index once.
cout << "after first if index is " << index <<endl;
}
}
if (index == 0) // if we didnt increment index during that operation
{
cout << "after second if num1 is " << num1 <<endl;
cout << "after second if index is " << index <<endl;
cout << "after second if num2 is " << num2 << endl;
cout << "after second if remainder is: " << remainder << endl;
cout << num1 << " is a prime number\n\n\n"; // it means that num1 is a prime number
}
}
cin.get();
return 0;

still havent gotten it to work, i have cout statements there because i want to see where the issue is, none of the couts from if(index == o) ever print for a range from 1-10. so im confused why that is.

thats the source code, here is the output:

Code:

after second for loop remainder is: 0
after first if index is 1
after first for loop num1 is 3
after first for loop index is 1
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 1
after first for loop num1 is 4
after first for loop index is 1
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 0
after first if index is 2
after second for loop num2 is 3
after second for loop remainder is: 1
after first for loop num1 is 5
after first for loop index is 2
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 1
after second for loop num2 is 3
after second for loop remainder is: 2
after second for loop num2 is 4
after second for loop remainder is: 1
after first for loop num1 is 6
after first for loop index is 1
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 0
after first if index is 2
after second for loop num2 is 3
after second for loop remainder is: 0
after first if index is 3
after second for loop num2 is 4
after second for loop remainder is: 2
after second for loop num2 is 5
after second for loop remainder is: 1
after first for loop num1 is 7
after first for loop index is 3
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 1
after second for loop num2 is 3
after second for loop remainder is: 1
after second for loop num2 is 4
after second for loop remainder is: 3
after second for loop num2 is 5
after second for loop remainder is: 2
after second for loop num2 is 6
after second for loop remainder is: 1
after first for loop num1 is 8
after first for loop index is 1
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 0
after first if index is 2
after second for loop num2 is 3
after second for loop remainder is: 2
after second for loop num2 is 4
after second for loop remainder is: 0
after first if index is 3
after second for loop num2 is 5
after second for loop remainder is: 3
after second for loop num2 is 6
after second for loop remainder is: 2
after second for loop num2 is 7
after second for loop remainder is: 1
after first for loop num1 is 9
after first for loop index is 3
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 1
after second for loop num2 is 3
after second for loop remainder is: 0
after first if index is 2
after second for loop num2 is 4
after second for loop remainder is: 1
after second for loop num2 is 5
after second for loop remainder is: 4
after second for loop num2 is 6
after second for loop remainder is: 3
after second for loop num2 is 7
after second for loop remainder is: 2
after second for loop num2 is 8
after second for loop remainder is: 1
after first for loop num1 is 10
after first for loop index is 2
after second for loop num2 is 1
after second for loop remainder is: 0
after first if index is 1
after second for loop num2 is 2
after second for loop remainder is: 0
after first if index is 2
after second for loop num2 is 3
after second for loop remainder is: 1
after second for loop num2 is 4
after second for loop remainder is: 2
after second for loop num2 is 5
after second for loop remainder is: 0
after first if index is 3
after second for loop num2 is 6
after second for loop remainder is: 4
after second for loop num2 is 7
after second for loop remainder is: 3
after second for loop num2 is 8
after second for loop remainder is: 2
after second for loop num2 is 9
after second for loop remainder is: 1