The program is suppose to output all the prime numbers between 3 and 100.
It acutally outputs all numbers between 3 and 100.

My code is as follows:

#include <iostream>
using namespace std;
int main ()
{
	int number=3, count=2;

	while (number <= 100)
	{
		if ((number % count) > 0)
		{
			cout << number << " ";
			number++;
			count = 2;
		}
		else
		{
			count++;
		}
	}
	cout << endl;

	return 0;
}

Does anyone see my mistake(s) and know what I need to do? Any help would be appreciated.

Walk through the execution of your program on paper. You'll be able to see the contents of the variables at each step and you can build a table of your expectations. Then run the program in a debugger and verify that the actual execution matches your expectations. Most likely you'll find bugs during the paper run that you can fix.

I took Narue's advice and found out that my code was a bunch of crap and rewrote the entire thing. It's working correctly now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.