Question
C++ create an output file with prime numbers in it: I did the program and it compiles but the file does not create??? Here is
C++ create an output file with prime numbers in it:
I did the program and it compiles but the file does not create??? Here is my code:
#include
bool isPrime(int);
int main() { fstream outfile; outfile.open("primesBefore100.txt");
outfile << "The prime numbers from 1 through 100." << endl; for (int num = 1; num <= 100; num++) {
if (isPrime(num)) outfile << num << endl; } outfile.close(); cin.get(); return 0; }
bool isPrime(int integer) {
if (integer == 1) return false;
for (int i = 2; i <= integer / 2; i++) { if (integer%i == 0) return false; } return true; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started