I'm having trouble with a problem for school. I know that I should do this myself so that I will remember it better, but I am having a difficult time with it.
I need to write a program that will output a list of all the prime numbers between 1 and x, including 1 and x and x is any number given by the user, using a nested loop.
for(int i = 0; /*CONDITION TO BE MET*/; ++i)
{
bool isPrime = true;
for(int j = 0; /*CONDITION TO BE MET*/; ++j)
{
if(NUMBER_ENTERED % j == 0) //If At Any Time A Number Between 0 and NUMBER_ENTERED Has No Remainder Then It Is Not Prime
{
isPrime = false;
}
}
if(isPrime)
{
std::cout << NUMBER_ENTERED << " ";
}
}
This is probably more help then I should have given you.
And @cppnewguy, good. I'm glad you're going to take my program and learn from it, rather than just use it for a grade. I was going to mention that but I forgot. Glad to know you're actually interested in learning.
It isn't but the OP's instructions said explicitly to output 1. I can only imagine that the professor is a bitter individual who has been forced to do things in projects that don't make any logical sense and now they are trying to bludgeon that feeling of complacency to their students.
1 isn't a prime number, but that doesn't make "The prime numbers between 1 and 100" an invalid statement. Just like "The even numbers between 3 and 9".
But if some one said "tell me the prime numbers between 1 and 7", I don't think I would say 7, it isn't between :)
Please remember that these posts are often homework problems (like this one). It is not acceptable on this forum to give out answers as whole code. You need to help the person learn how to do it themselves. I know you want to show off your coding skills but in the long run doing someones homework for them will end up with them failing their class when they can't pass their tests.
Keep working on the prime number code though, it's a good practice problem!
EDIT: Oop, missed the continue, Computergeek is right, odd numbers.