The program compiles and runs, but errors out at the beginning of the do-while loop. Any suggestions are greatly appreciated.
It's possible it's the combination of the do-while and the for loop. Or perhaps my modulus calculation is wrong.
void printNum(int primeNum);
int main()
{
int startRange, endRange;
int count=0;
int divisor = 2;
int remainder;
// enter a range of numbers
cout << "Enter the starting number of your range: \n";
cin >> startRange;
cout << "Enter the ending number of your range: \n";
cin >> endRange;
// startRange
// endRange
// run code to determine which numbers within the range are prime
//for every number in range, find the remainder
do
{for (count = startRange; count<= endRange; count++)
remainder = count%divisor;
}while (remainder != 0);
divisor++;
if (divisor == count){
printNum(count);
}
else{
cout << "There are no prime numbers in your range.\n";
} //function
system("pause");
return 0;
}
// prime - run function
// function - prints num
/***************
printNum
***************/
void printNum(int primeNum)
{
cout << primeNum << endl;
}
int calcPrime(int);
int main()
{
int startRange, endRange;
int count;
cout << "Enter the starting number of your range: \n";
cin >> startRange;
cout << "Enter the ending number of your range: \n";
cin >> endRange;
for (count = startRange; count <= endRange; count++)
{ calcPrime(count);
}
system("pause");
return 0;
}
/****
calcPrime
******/
int calcPrime(int num)
{ int divisor=2;
int remainder;
do
{remainder = num%divisor;
divisor++;
}
while (remainder !=0);
if (--divisor == num)
return num;
}
// more_functions
#include "stdafx.h"
#include <iostream>
usingnamespace std;
void calcPrime (int);
int main()
{
int startRange, endRange;
cout << "Enter the first number in your range:\n";
cin >> startRange;
cout << "Enter the end number in your range:\n";
cin >> endRange;
do
{calcPrime(startRange);
startRange++;
}while (startRange <= endRange);
system("pause");
return 0;
}
/*****
calcPrime
*****/
void calcPrime (int num)
{
int divisor=2;
int remainder;
do
{remainder = num%divisor;
divisor++;
}
while (remainder !=0);
if (--divisor == num){
cout << num << endl;
}
}