Expression must have a modifiable lvalue

What's the problem with this code?
I want to make a prime checker
I use the following formula
If a number nr is prime, than this equation will be true
(nr-1)!+1%nr=0
So the equation will have no remainder.
I am a beginner to programming so don't judge
And if you find any other mistakes, tell me so I can learn.
Thanks!

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
  #include <iostream>
#include <conio.h>
#include <fstream>

using namespace std;

int fact(int n);
void prim(int nr);

int main() {
	int nr=1;
	while (true) {
		nr++;
		prim(nr);
	}

}

int fact(int n)
{
	return (n == 1 || n == 0) ? 1 : fact(n - 1) * n;
}

void prim(int nr) {
	if ((fact(nr-1) + 1)%nr=0) {
		ofstream Prime;
		Prime.open("prime.txt");
		Prime << nr << endl;
		Prime.close;
	}
}
= is not the same as ==

Do not use = when you meant to use ==
Last edited on
Topic archived. No new replies allowed.