SlideShare a Scribd company logo
1 of 4
Download to read offline
What is wrong with my source file that it will not compile?
// Is Prime Function
// Author: Lila Bailey
// Date: 11/03/2016
#include "time.h"
#include
#include
using namespace std;
// Function Prototype
bool isPrime(int);
int main()
{
// Variable declaration
fstream outfile(int);
int num;
// Open an output file
outfile.open("primesBefore100.txt")
//Repeat loop 100 times
for (int num = 1; num <= 100; num++)
{
//call isPrime function with each variable
if (isPrime(num))
outfile << num << endl;
}
//close output file
outfile.close(int);
system("pause");
return 0;
}
//**************************************************************
// The isPrime function determines whether a number is prime. *
// It displays "Is a prime number" or "Is not a prime number" *
//**************************************************************
bool isPrime(int num)
{
int count = 0;
for (int i = 2; i <= num / 2; i++)
{
if (num%i == 0)
count++;
}
if (count > 0)
return false;
else
return true;
}
Solution
Hi,
I have fixed the issue It is working fine now and highlighted the code changes beow.
#include "time.h"
#include
#include
using namespace std;
// Function Prototype
bool isPrime(int);
int main()
{
// Variable declaration
ofstream outfile;
int num;
// Open an output file
outfile.open("primesBefore100.txt");
//Repeat loop 100 times
for (int num = 1; num <= 100; num++)
{
//call isPrime function with each variable
if (isPrime(num))
outfile << num << endl;
}
//close output file
outfile.close();
system("pause");
return 0;
}
//**************************************************************
// The isPrime function determines whether a number is prime. *
// It displays "Is a prime number" or "Is not a prime number" *
//**************************************************************
bool isPrime(int num)
{
int count = 0;
for (int i = 2; i <= num / 2; i++)
{
if (num%i == 0)
count++;
}
if (count > 0)
return false;
else
return true;
}
Output:
primesBefore100.txt
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

More Related Content

Similar to What is wrong with my source file that it will not compile Is P.pdf

File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
RutujaTandalwade
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
eyeonsecuritysystems
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
aryan532920
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
humphrieskalyn
 

Similar to What is wrong with my source file that it will not compile Is P.pdf (20)

Systemcall1
Systemcall1Systemcall1
Systemcall1
 
General Functions
General FunctionsGeneral Functions
General Functions
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
slides3_077.ppt
slides3_077.pptslides3_077.ppt
slides3_077.ppt
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Data File Handiling File POINTERS IN C++
Data File Handiling File POINTERS IN C++Data File Handiling File POINTERS IN C++
Data File Handiling File POINTERS IN C++
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Python an-intro youtube-livestream-day4
Python an-intro youtube-livestream-day4Python an-intro youtube-livestream-day4
Python an-intro youtube-livestream-day4
 
File & Exception Handling in C++.pptx
File & Exception Handling in C++.pptxFile & Exception Handling in C++.pptx
File & Exception Handling in C++.pptx
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
 
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
 
As400 session or device error
As400   session or device errorAs400   session or device error
As400 session or device error
 
Ansible 2.0
Ansible 2.0Ansible 2.0
Ansible 2.0
 
Fail2ban
Fail2banFail2ban
Fail2ban
 
w10 (1).ppt
w10 (1).pptw10 (1).ppt
w10 (1).ppt
 
Rest in practice con Symfony2
Rest in practice con Symfony2Rest in practice con Symfony2
Rest in practice con Symfony2
 

More from armsnoida

In your own words does Enclave as a unit of security does it describe.pdf
In your own words does Enclave as a unit of security does it describe.pdfIn your own words does Enclave as a unit of security does it describe.pdf
In your own words does Enclave as a unit of security does it describe.pdf
armsnoida
 
How did the issues of sectionalism reemerge in 1850, what was the pr.pdf
How did the issues of sectionalism reemerge in 1850, what was the pr.pdfHow did the issues of sectionalism reemerge in 1850, what was the pr.pdf
How did the issues of sectionalism reemerge in 1850, what was the pr.pdf
armsnoida
 
How is localization of Gap gene expression achieved in the Drosophil.pdf
How is localization of Gap gene expression achieved in the Drosophil.pdfHow is localization of Gap gene expression achieved in the Drosophil.pdf
How is localization of Gap gene expression achieved in the Drosophil.pdf
armsnoida
 
Explain the concept of diaspora and distinguish between voluntary and.pdf
Explain the concept of diaspora and distinguish between voluntary and.pdfExplain the concept of diaspora and distinguish between voluntary and.pdf
Explain the concept of diaspora and distinguish between voluntary and.pdf
armsnoida
 
Bullying has become increasingly problematic for school aged childre.pdf
Bullying has become increasingly problematic for school aged childre.pdfBullying has become increasingly problematic for school aged childre.pdf
Bullying has become increasingly problematic for school aged childre.pdf
armsnoida
 

More from armsnoida (20)

Match appropriately. Best fit. stratum corneum papillary region ad.pdf
Match appropriately. Best fit.  stratum corneum  papillary region  ad.pdfMatch appropriately. Best fit.  stratum corneum  papillary region  ad.pdf
Match appropriately. Best fit. stratum corneum papillary region ad.pdf
 
In your own words does Enclave as a unit of security does it describe.pdf
In your own words does Enclave as a unit of security does it describe.pdfIn your own words does Enclave as a unit of security does it describe.pdf
In your own words does Enclave as a unit of security does it describe.pdf
 
I need help answering both these questionsQuestion 5 1. A dip.pdf
I need help answering both these questionsQuestion 5 1. A dip.pdfI need help answering both these questionsQuestion 5 1. A dip.pdf
I need help answering both these questionsQuestion 5 1. A dip.pdf
 
How would you investigate the question about the probability of matc.pdf
How would you investigate the question about the probability of matc.pdfHow would you investigate the question about the probability of matc.pdf
How would you investigate the question about the probability of matc.pdf
 
How did the issues of sectionalism reemerge in 1850, what was the pr.pdf
How did the issues of sectionalism reemerge in 1850, what was the pr.pdfHow did the issues of sectionalism reemerge in 1850, what was the pr.pdf
How did the issues of sectionalism reemerge in 1850, what was the pr.pdf
 
How is localization of Gap gene expression achieved in the Drosophil.pdf
How is localization of Gap gene expression achieved in the Drosophil.pdfHow is localization of Gap gene expression achieved in the Drosophil.pdf
How is localization of Gap gene expression achieved in the Drosophil.pdf
 
For the following ordinary differential equations, identify their de.pdf
For the following ordinary differential equations, identify their de.pdfFor the following ordinary differential equations, identify their de.pdf
For the following ordinary differential equations, identify their de.pdf
 
Find two models of incidence geometry, each with exactly four points.pdf
Find two models of incidence geometry, each with exactly four points.pdfFind two models of incidence geometry, each with exactly four points.pdf
Find two models of incidence geometry, each with exactly four points.pdf
 
Finish the following natural deduction proofs SolutionThe two .pdf
Finish the following natural deduction proofs SolutionThe two .pdfFinish the following natural deduction proofs SolutionThe two .pdf
Finish the following natural deduction proofs SolutionThe two .pdf
 
Find the most general f. Use C for the constant of the first anti-de.pdf
Find the most general f. Use C for the constant of the first anti-de.pdfFind the most general f. Use C for the constant of the first anti-de.pdf
Find the most general f. Use C for the constant of the first anti-de.pdf
 
Explain the concept of diaspora and distinguish between voluntary and.pdf
Explain the concept of diaspora and distinguish between voluntary and.pdfExplain the concept of diaspora and distinguish between voluntary and.pdf
Explain the concept of diaspora and distinguish between voluntary and.pdf
 
Does S_2 span P_2 Solutionlets calculate the dimension of S_2.pdf
Does S_2 span P_2 Solutionlets calculate the dimension of S_2.pdfDoes S_2 span P_2 Solutionlets calculate the dimension of S_2.pdf
Does S_2 span P_2 Solutionlets calculate the dimension of S_2.pdf
 
Describe one exception to Mendelian inheritance In what year did Cha.pdf
Describe one exception to Mendelian inheritance  In what year did Cha.pdfDescribe one exception to Mendelian inheritance  In what year did Cha.pdf
Describe one exception to Mendelian inheritance In what year did Cha.pdf
 
Describe Norman’s 7 Stages of Action and Four Principles of Good Des.pdf
Describe Norman’s 7 Stages of Action and Four Principles of Good Des.pdfDescribe Norman’s 7 Stages of Action and Four Principles of Good Des.pdf
Describe Norman’s 7 Stages of Action and Four Principles of Good Des.pdf
 
Consider a system of two components, connected as shown in the diagr.pdf
Consider a system of two components, connected as shown in the diagr.pdfConsider a system of two components, connected as shown in the diagr.pdf
Consider a system of two components, connected as shown in the diagr.pdf
 
Bullying has become increasingly problematic for school aged childre.pdf
Bullying has become increasingly problematic for school aged childre.pdfBullying has become increasingly problematic for school aged childre.pdf
Bullying has become increasingly problematic for school aged childre.pdf
 
An experiment was conducted to determine whether a deficiency of carb.pdf
An experiment was conducted to determine whether a deficiency of carb.pdfAn experiment was conducted to determine whether a deficiency of carb.pdf
An experiment was conducted to determine whether a deficiency of carb.pdf
 
An abject is orbiting the Earth at 215 miles in altitude. It takes o.pdf
An abject is orbiting the Earth at 215 miles in altitude. It takes o.pdfAn abject is orbiting the Earth at 215 miles in altitude. It takes o.pdf
An abject is orbiting the Earth at 215 miles in altitude. It takes o.pdf
 
A protein that was isolated by a team of university scientists is su.pdf
A protein that was isolated by a team of university scientists is su.pdfA protein that was isolated by a team of university scientists is su.pdf
A protein that was isolated by a team of university scientists is su.pdf
 
3 Quiz Question 10 (of 11) If the cash is received before the related.pdf
3 Quiz Question 10 (of 11) If the cash is received before the related.pdf3 Quiz Question 10 (of 11) If the cash is received before the related.pdf
3 Quiz Question 10 (of 11) If the cash is received before the related.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

What is wrong with my source file that it will not compile Is P.pdf

  • 1. What is wrong with my source file that it will not compile? // Is Prime Function // Author: Lila Bailey // Date: 11/03/2016 #include "time.h" #include #include using namespace std; // Function Prototype bool isPrime(int); int main() { // Variable declaration fstream outfile(int); int num; // Open an output file outfile.open("primesBefore100.txt") //Repeat loop 100 times for (int num = 1; num <= 100; num++) { //call isPrime function with each variable if (isPrime(num)) outfile << num << endl; } //close output file outfile.close(int); system("pause"); return 0; } //************************************************************** // The isPrime function determines whether a number is prime. * // It displays "Is a prime number" or "Is not a prime number" * //************************************************************** bool isPrime(int num) {
  • 2. int count = 0; for (int i = 2; i <= num / 2; i++) { if (num%i == 0) count++; } if (count > 0) return false; else return true; } Solution Hi, I have fixed the issue It is working fine now and highlighted the code changes beow. #include "time.h" #include #include using namespace std; // Function Prototype bool isPrime(int); int main() { // Variable declaration ofstream outfile; int num; // Open an output file outfile.open("primesBefore100.txt"); //Repeat loop 100 times for (int num = 1; num <= 100; num++) { //call isPrime function with each variable if (isPrime(num)) outfile << num << endl; }
  • 3. //close output file outfile.close(); system("pause"); return 0; } //************************************************************** // The isPrime function determines whether a number is prime. * // It displays "Is a prime number" or "Is not a prime number" * //************************************************************** bool isPrime(int num) { int count = 0; for (int i = 2; i <= num / 2; i++) { if (num%i == 0) count++; } if (count > 0) return false; else return true; } Output: primesBefore100.txt 1 2 3 5 7 11 13 17 19 23 29 31