My loop is not so infinite?
They say the best way to learn programming is to learn by doing, and that's why I've made this :
Code:
#include <iostream>
using namespace std;
// Prime number function - Tests number for remainder. If none is found, return false. Otherwise, return true.
bool PrimeFunction()
{
int n;
cin >> n;
cin.ignore();
while (n)
{
if (n % 2 == 0)
{
cout << "Number is not prime";
return false;
}
else
{
cout << "Number is prime";
return true;
}
}
}
int main()
{
cout << "Enter a number and press enter: \n";
PrimeFunction();
cin.get();
return 0;
}
What I'm trying to do is fairly obvious, and it works, just not the way I want it to. The problem is, after you have input the number and it tells you the result, on the next press of enter the program ends. What I want it to do is after you've pressed enter and the result is printed, the program lets you enter another number to be tested, rather than ending. I do apologise for the clear-as-mud description but I can't think of another way of wording it.
What do I need to change about the program to get it to do that? I also apologise for the indenting, it looks great in SCiTE, but awful here.