So I have a programming assignment in which I'm asked to display all of the prime numbers between 1 and 100 using nested loops. And I'm also asked to display the quantity of numbers that are primes between 1 and 100.
So here is the code I wrote that addresses the first part, but I didn't get to the second requirement yet.
I haven't placed any statements in the else-if or else brackets because I don't need to do anything if they evaluate to be true.Code:int x = 1; int loop2 = 2; while (loop2<100){ loop2++; x++; while (x < loop2){ if ((loop2 % x != 0) && (loop2 < 100)){ std::cout << loop2 << std::endl; } else if (loop2 % x == 0){ } else{ } } }
So when I compile and run this, I see an endless repeating string of 3's in the output of the console. So I'm obviously doing something very wrong, and it has to do with my logic, but I can't figure out what exactly is wrong with my logic.
If someone could point me in the right direction with regards to what is wrong with my logic, I would really appreciate it!