Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include using namespace std;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

Students also viewed these Databases questions

Question

What is a POP?

Answered: 1 week ago