Alright have finally done it. And this is my code. See if there is anything that could be truncated or left off. I appreciate it. And thanks Cornedbee for clarifying the question.
Code:
#include <iostream>
#include <math.h>
using namespace std;
// Function must be declared before being used.
int prime(int n);
int main(){
int i;
// Set up an infinite loop; break if user enters 0.
// Otherwise, evaluate n from prime-ness.
while(1){
cout << "Enter a number (0 to exit)";
cout << "and press ENTER: ";
cin >> i;
if(i == 0)
break;
for(i = 2; i <= 22; i++) // Test all numbers from 2 to 22
if(prime(i)){ // state for each mumber whether it is a prime
cout<< i << "is prime" << endl; // and print out all numbers.
}else{
cout<< i << "is not a prime" << endl;
}
}
return 0;
}
// Prime number function. Test divisors from
// 2 to sqrt of n. Return false if a divisor
// found; otherwise, return true.
int prime(int n){
int i;
for(i = 2; i <= sqrt((double) n); i++)
if(n % i == 0)
return false; // n is not prime.
return true; // If no divisor found, n is prime.
}