Code:
#include <iostream>
#include <math.h>
using namespace std;
int prime(int n);
int main()
{
int i; int being declared here as i
while (1)
{
cout << "Enter a number (0 to exit) and press ENTER: ";
cin >> i; User input now defined as i
if (i == 0)
break;
if (prime(i))
cout << i << " is prime" << endl;
else
cout << i << " is not prime" << endl;
}
cout << endl;
system("PAUSE");
return 0;
}
int prime(int n)
{
int i; Int i now declared a 2nd time
double sqrt_n = sqrt(static_cast<double>(n));
for (i = 2; i <= sqrt_n); i++) Int i now defined a 2nd time as 2
{
if (n % i == 0)
return false;
}
return true;
}
Am I wrong in what I am saying? I have put my comments in green

