![]() |
|
#1
|
|||
|
|||
While loop help!Ok, I'm writing a program to determine if the number entered is prime. So, here is my main script:
CPP / C++ / C Code:
You can see where I pointed out my problem ( I think). Can I input a arthmatic operator here to process every # inputted to determine the if condition? Basically, every prime number modulous 2 puts out a 1, so I can determine if the # is prime or not by the if condition. Thanks for any help. |
|||
|
#2
|
|||
|
|||
Re: While loop help!Quote:
Consider the value 9. 9 % 2 == 1, but 9 is not prime. |
|
#3
|
|||
|
|||
Re: While loop help!Ok.
2 questions: 1. What would be the most simplest and correct way to determine if the number is prime? 2. Is my code correct? |
|
#4
|
|||
|
|||
Re: While loop help!As I've wrote my code a little different, I've tested all numbers and everything is coming out as expected. Now, I just need to integrate my while loops. What is wrong (programming wise) with my code?
|
|
#5
|
|||
|
|||
Re: While loop help!What code?
You know, finding prime has been covered here before. It might help you to search the forum for previous threads. |
|
#6
|
|||
|
|||
Re: While loop help!Quote:
I'm now asking for help about my while loop, not process of determining a prime number. The code in the first reply if you would of read it. |
|
#7
|
|||
|
|||
Re: While loop help!Quote:
Quote:
|
|
#8
|
|||
|
|||
Re: While loop help!Quote:
I'm still tying to register that sentence in my head. Could you elaborate? As for my while structure. When the user enters the values, shouldn't that be in the outer loop? |
|
#9
|
|||
|
|||
Re: While loop help!Quote:
Quote:
Does the new code still rely on this to determine a prime number? : CPP / C++ / C Code:
|
|
#10
|
|||
|
|||
Re: While loop help!Quote:
So look at a number of examples:
Quote:
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classic recursion game of 8 Queens errors | BKizzle77 | Java Forum | 11 | 11-Aug-2008 01:35 |
| Exiting an infinite loop. | memmudu | C++ Forum | 1 | 31-Dec-2007 07:25 |
| breaking an infinite loop through stdin | pisuke | C Programming Language | 9 | 03-Jul-2007 21:19 |
| Text-Based Roulette Game | mfm1983 | C++ Forum | 5 | 29-Nov-2006 13:20 |
| messy loop help please | sammacs | C Programming Language | 6 | 26-Nov-2004 16:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The