Prime calculates missing in C++
I've made a piece of code that just will not work, what's wrong! It can execute fine, but calculates everything as being non prime!
Thanks in advance!
Code:
# include <iostream>
# include <cstdlib>
# include <cmath>
using namespace std;
int main ()
(
int t, c, residue;
char in;
Cout << "Enter the number you want tested for primtalisme, then enter: \ n \ n";
cin>> t;
c = t;
if (t == 0, t == 1, t == 2)
(
Cout << "yes";
Cout <<c;
Cout << "suffering from primtalisme012 \ n \ n";
return 0;
)
else
(
for (i = 2; i <= (c-1); i + +)
(
if (c% in == 0)
(
residual = 0;
break;
)
else
(
residual = 1;
)
)
if (remainder == 0)
(
Cout << "yes";
Cout <<c;
Cout << "suffering from primtalisme other \ n \ n";
)
else
(
Cout << "no";
Cout <<c;
Cout << "suffer not the primtalisme \ n \ n";
)
)
return 0;
)
PS. I know there are other methods, but why does this not?
Re: Prime calculates missing in C++
You have written your first if false statements.
will be
if (i == 0 | | i == 1 | | i == 2)
Note two pipes | | instead of,
And it never come into your first loop because of the type that char when you compare with an int should also be of the type.
And if your last statement with the rest seem to have reversed incorrectly.
If residual == 0, then you run into a second number to go up in the input number, but you wonder about the opposite.
Re: Prime calculates missing in C++
If we try with 3 (3 is a prime number)
Code:
for(i=2; i<=(c-1); i++)
{
if(c%i==0)
To test at:
IF 3% 2 EQUAL TO 0
Prime =
Which of course, return false. And it is wrong.