Problem running prime number test.
Code:
#include <stdafx.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n; // Number to test for prime-ness
int i; // Loop counter
int is_prime; // Boolean flag
//Assume that a number is prime until proven
//otherwise
is_prime = true;
//Get a number from the keyboard.
cout << "Enter a number and press ENTER: ";
cin >> n;
//Test for prime-ness by checking for divisibility
//by all whole numbers from 2 to sqrt(n).
i = 2;
while (i <= sqrt(static_cast<double>(n)))
{
if (n % i == 0)
is_prime = false;
i++;
}
//Print results
if (is_prime)
cout << "Number is prime.";
else
cout << "Number is not prime.";
return 0;
}
This program was written in Visual C++ Express on a CLR Console Application template. The problem that I'm having is that the program won't run when I hit Ctrl+F5 and I get an error message that says 'There were building errors'. My guess is that the <math.h> library might not be included in the express edition or perhaps I haven't installed it or something. But I wanted to post it here just in case I was missing any obvious mistake that I'm not seeing.
NOTE: This is a noob programmer speaking. Been writing code for about 4 days total so keep that in mind.