with this new code I rewrote to determine if a number is prime or not, the code works. My problem is that it only runs the program once, and I want it to keep going. Any help would be appreciated on where to fix the code.
#include <iostream>
using std:cin;
using std:cout;
using std:endl;
#include <cmath>
int main() {
unsignedlong n;
while (cin>>n) {
for (int i=1; i<=n; i++)
{
if (n==0)
{
cout<<"0"<<endl;
}
elseif (n%2==0 && n!=2)
{
cout<<"0"<<endl;
}
elseif (n%3==0)
{
cout<<"0"<<endl;
}
elseif (n%5==0)
{
cout<<"0"<<endl;
}
elseif (n%7==0)
{
cout<<"0"<<endl;
}
else
{
cout<<"1"<<endl;
}
return 0;
}
}
}
You can now see that you have a return 0; within your inner for loop. This immediately ends your program. There's other issues as well, but removing the return statement is a good start.