Hi there i'm trying to make a function in C++ that takes a number, i, and decides if it is a prime number or not by running through a loop to find it's multiples, and then makes sure it isn't prime through a series of test. However, it seems the loop isn't even being run through. I've told it to output no matter where in the loop it is, but I get no outputs. Here is the code:
#include <iostream>
using namespace std;
int main()
{
int j =1;
int z = 0;
int i = 10;
bool p = false;
while (p = false){
cout << "not starting ifs";
z=i%j;
if (z==0 && j>2){
p=true;
cout << "not prime" << endl << "loops to if";
}
else if (j==1){
j++;
cout <<"loops to else if 1";
}
else if ( i==2 || j==i ){
p = true;
cout << "prime" << endl << "loops to else if 2";
}
else {
j++;
cout << "loops to else";
}
}
return 0;
}
I don't care whether or not the math behind it is right, I want to figure that out myself for the learning experience. But if anyone could help me figure this out with a good easy to understand explanation I would appreciate it! I"m really new to programming, so I'm not used to jargon yet. I look forward to your advice!