Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-11-2008
Member
 
Join Date: Oct 2008
Posts: 30
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?
Reply With Quote
  #2  
Old 21-11-2008
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #3  
Old 21-11-2008
Member
 
Join Date: Apr 2008
Posts: 1,948
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Prime calculates missing in C++"
Thread Thread Starter Forum Replies Last Post
MS Project 2007 - Parent Task Calculates Duration Incorrectly freakp Windows Software 3 28-02-2012 07:47 PM
The ASUS Transformer Prime TF700 lot better than earlier prime Roustagi Portable Devices 7 24-01-2012 06:49 AM
Problem with C# program which calculates the prime number $Bird$ Software Development 4 29-11-2010 12:54 PM
Prime number mad4jack Software Development 3 03-10-2008 09:24 PM


All times are GMT +5.5. The time now is 10:23 PM.