Finding prime numbers 1-100 and write them to file.
Can someone help me figure out how to find all the prime numbers between
1-100 and write them to a file?
#include<iostream>
#include<fstream>
using namespace std;
bool isPrime(int);
int main()
{
int iNum;
cout << "This program will calculate and store all the prime numbers
between 1 and
100 "<<endl;
ofstream myfile( "writeto.txt" );
for(int i = 1; i <= 100; i++)
{
isPrime(i);
while(isPrime(i) == true)
{
myfile << i <<endl;
break;
}
myfile.close();
return 0;
}
}
bool isPrime(int iNum)
{
bool status;
if( iNum <= 1 )
return false;
for( int i = 2; i < iNum; i++ )
{
if( iNum % i == 0 )
return false;
}
return true;
}
How can I get this to work? I have been working on this for a while and
think it has to do something with my return. I am really lost and hope
someone can help me. I am not looking for answers I just want someone to
point me in the right direction.
No comments:
Post a Comment