URGENT HELPPP

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int count=1;
int divisor=2;
double x,squareRoot;
cin>>x;
squareRoot=sqrt(x);
while(divisor<=sqrt(x))
{
if(x mod divisor==0)
{
cout<<"x is not a prime number"<<endl;
count=count+1;
}
else if(x mod divisor!=0)
{
cout<<"x is a prime number"<<endl;
}
divisor=divisor+1;
}
return 0;
}

I HAVE WRITTEN THIS CODE AND WHEN I RUN IT COMPILER GIVES ERROR OF EXPECTED '>' before 'mod'
help plz!
I don't get what your program is supposed to do. Maybe describing the program will help.

FYI, you can get the program to compile with minor changes.

See what I did below; my code compiles without issue based on your post:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>

#include<cmath>

using namespace std;

int main(int argc, char** argv)

{
	int count = 1;
	int divisor = 2;
	int x;
	double squareRoot;
	cin >> x;

	squareRoot = sqrt((double)x);

	while (divisor <= sqrt((double)x))

	{
		if (x % divisor == 0)
		{
			cout << x << " is not a prime number" << endl;
			count = count + 1;
		}
		else if (x % divisor != 0)
		{
			cout << x << " is a prime number" << endl;
		}
		divisor = divisor + 1;
	}

	return EXIT_SUCCESS;

}
You can't use the word "mod", you have to use the symbol "%"
Yep, that wasn't his only problem though...
Topic archived. No new replies allowed.