+ 2

What am i doing wrong?

trying to make a code to display all numbers with a "prime"-" not prime code" https://code.sololearn.com/c13KtZRG5gfD/?ref=app

13th Feb 2018, 12:29 AM
Teddy Baka (Teddy)
Teddy Baka (Teddy) - avatar
6 Answers
+ 9
Just some syntax errors, btw the logic behind the code is not the right one to collect prime numbers, keep in mind that Sololearn will return a "Time Limit Exceeded". Protip: indent the code. Useful link: https://www.programiz.com/cpp-programming/examples/prime-number https://code.sololearn.com/cYm3ZIEnjHDO/?ref=app
13th Feb 2018, 12:50 AM
Maz
Maz - avatar
+ 4
A couple of errors: - one isn't really a good starting point as it divides into everything, - while loop goes for a long time until number overflows into negative numbers, - number/number is always 1 so everything is going to be called a prime, and - you will get time limit exceeded error aborting your code before it finishes executing. Start simple do ten numbers to prove you got things right. Start number at 2. Change your while to while (number <= 10). Primes can't be divided by any numbers between 2 and number/2 so you need a testing loop to check this.
13th Feb 2018, 1:02 AM
John Wells
John Wells - avatar
+ 4
yeah I noticed that, it still will spit out a bunch of numbers, also the first part in the if Will never work out I was mostly just trying to write my fist code
13th Feb 2018, 1:03 AM
Teddy Baka (Teddy)
Teddy Baka (Teddy) - avatar
+ 3
Try outputting 2 to 10 first
13th Feb 2018, 1:05 AM
John Wells
John Wells - avatar
+ 2
alright thanks, let's see how it works out
13th Feb 2018, 1:06 AM
Teddy Baka (Teddy)
Teddy Baka (Teddy) - avatar
0
ohhh thank you, I see where I was wrong :)
13th Feb 2018, 12:54 AM
Teddy Baka (Teddy)
Teddy Baka (Teddy) - avatar