I want the program to run until the user types something other than 1.
#include <stdio.h>
#include <iostream>
using namespace std;
int run = 1;
int main()
{
do {
int max, oneless; // I use oneless to give myself one less number than the max
// This is so we can go from 0-99 if max was set to 100
cout << "Please enter a number to check for all Prime numbers" << endl;
cout << "using The Sieve Of Eratosthenes: ";
cin >> max;
oneless = max-1;
int num[max], i, j;
for(i=0;i<=max;i++) {
num[i]=i+1;
}
for(i=1;i<=oneless;i++)
{
if(num[i]!=0)
{
for(j=(i+1);j<=oneless;j++)
{
if(num[j]!=0)
{
if((num[j]%num[i])==0)
num[j]=0;
/*check if num[j] is a multiple of num[i]*/
/*if it is a multiple then set it to 0*/
}
}
}
}
for(i=1;i<=oneless;i++)
{
if(num[i]!=0) { /* Print all numbers still flagged as Prime(=1) */
cout << "Prime: " << num[i] << endl;
}
}
cout << "Would you like to run this program again?" <<endl;
cout << "Type 1 for Yes, 0 for No: ";
cin >> run;
return 0;
} while (run==1);
}
Thanks for the help.

New Topic/Question
Reply




MultiQuote




|