Corrections on School assignment...
I used some examples for calculating prime numbers up to 50,000 and had a code that worked great (no user input which is what the instructor wanted. But she clarified and said she actually wanted the output to look somethihng like this:
Start End Number of Primes
1 1000 168
1001 2000 135
2001 3000 127
3001 4000 120
4001 5000 119
5001 6000 114
6001 7000 117
7001 8000 107
8001 9000 110
9001 10000 112
…
…
…
49001 50000 98
Total primes in the first 50 chiliads: 5133
Average number per chiliad: 102.66
Okay so I've been working on this and at first I had it outputting primes in one column and zeros in another in an infinite loop untill I nested a while loop in a for loop. Ignoring the bottom 2 lines of output (I'll figure out those later) please look at what I have and help me understand why I get NO output.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void prime_num(int);//Void to specify no function type.
int primeCount = 0, numCount1 = 0, numCount2 = 0, rangeStart = 1, rangeEnd = 1000;
int main()
{
int num = 50000; //Establishing variables
prime_num(num);
}
void prime_num( int num)
{
bool isPrime = true;
for ( int num2 = 2; num2 <= num; num2++)
{
for ( int num3 = 2; num3 < num2; num3++)//Forloops to create count.
{
if ( num2 % num3 == 0 )//if with a mod to test for !prime.
{
isPrime = false;
break;//break from if...
for(isPrime; numCount1 < 1000 && numCount2 < 50000; numCount1++);
{
primeCount++;
numCount2++;
break;
while(numCount1 >= 1000)
{
cout << rangeStart << setw(5) << rangeEnd << setw(5)<< primeCount << endl;//Print the range and the current primeCount for it
primeCount = 0; //Reset primeCount and numCount1
numCount1 = 0;
rangeStart = rangeStart + 1000;
rangeEnd = rangeEnd + 1000;
break//break from while to reset the ranges and and first two counts
}
}
}
}
isPrime=true;
}
system("pause");
}
//
PLEASE HELP I have one more day to reSubmit it.