I wrote this code for c++ on Dev C++ and it says my ??WHILE?? phrase is incorrect Please help.
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n; //number to test for primeness
int i; //loop counter
int is_prime = true; //Boolean flag...
//assume true for now
//Get a number from the keyboard
cout << "Enter a number and press ENTER:";
cin >> n;
//Test for prime by checking for divisibilitty.
//by alll whole numbers from 2 to sqrt(n).
i = 2;
while (i <= sqrt(n) ) { //while i is <= sqrt(n)
if (n % i == 0) // if i divides n.
is_prime = false; // n is not prime
i++; //add 1 to i
}
//print results
if (is_prime)
cout << "Number is prime." << endl;
else
cout << "Number is not prime." << endl;
1. We would like to have the COMPLETE error.
2. Dev-C++ is considered outdated on this forum. You can take Code::Blocks here: http://www.codeblocks.org/downloads/26 , or you can take wxDev-C++ (it's NOT Dev-C++!!) or VS08 Express, that's completely free.
3. You are suggested not to use that system("PAUSE");.
Here's the reason: http://cplusplus.com/articles/j3wTURfi/
Thank you so much it now works. I am very new to C++ and am learning from a book my aunt gave me a few years back thus is why i am using such an old program.