My homework assignment is to:
Project 6 Description:
Quote
This program requires the utilization of concepts in Chapter 5 and Chapter 6. This program uses
two methods to determine the prime numbers that exist between 2 and a maximum value provided by the
user. The prime numbers along with some other information is written to an output file specified by the
user.
The program is to run in a loop controlled by the maximum value entered by the user. As long as
the value is greater than or equal to 2, the program executes. For values less than 2, the program
terminates. Each time through the program, the user enters the name for an output file. Run the sample
solution to understand how the program is to operate
The overall construct of the program is an outer loop that is controlled by the maximum value
entered by the user (use a while loop). Inside this loop, the output file is prompted for and opened, and
the two methods for determining the prime numbers are run. Each method requires 2 for loops (for loops
are much better suited for this part of the problem than are while loops). The outer loop runs through all
the possible numbers to test, and the inner loop performs the test on the outer loop numbers.
For each of the two methods used to determine the prime numbers, a loop iteration counter, that
counts how many times the loops are executed, and an event counter, that counts the number of prime
numbers found, are needed. The prime numbers are written to the output file as they are found. Use a
field width of 5 and left justification when printing out the prime numbers. Each time the outer loop OR
the inner loop is executed, the iteration counter is to be incremented.
Since two methods are going to be compared, each method should have its own variables for the
iteration counter and event counter.
two methods to determine the prime numbers that exist between 2 and a maximum value provided by the
user. The prime numbers along with some other information is written to an output file specified by the
user.
The program is to run in a loop controlled by the maximum value entered by the user. As long as
the value is greater than or equal to 2, the program executes. For values less than 2, the program
terminates. Each time through the program, the user enters the name for an output file. Run the sample
solution to understand how the program is to operate
The overall construct of the program is an outer loop that is controlled by the maximum value
entered by the user (use a while loop). Inside this loop, the output file is prompted for and opened, and
the two methods for determining the prime numbers are run. Each method requires 2 for loops (for loops
are much better suited for this part of the problem than are while loops). The outer loop runs through all
the possible numbers to test, and the inner loop performs the test on the outer loop numbers.
For each of the two methods used to determine the prime numbers, a loop iteration counter, that
counts how many times the loops are executed, and an event counter, that counts the number of prime
numbers found, are needed. The prime numbers are written to the output file as they are found. Use a
field width of 5 and left justification when printing out the prime numbers. Each time the outer loop OR
the inner loop is executed, the iteration counter is to be incremented.
Since two methods are going to be compared, each method should have its own variables for the
iteration counter and event counter.
and here is the code i have thus far:
// Lab Section 01 #
// 07/06/06 #
// This Program Will Determine All Prime #
// Numbers Between 2 And A Given Number #
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
int input;
bool Prime = true;
string filename;
cout << "Enter In A Number To Be Tested: " << endl;
cin >> input;
cout << "Enter The Name Of The Output File: " << endl;
cin >> filename;
//###################### FIRST METHOD !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
while( input >= 2)
{
ofstream P6;
P6.open(filename.c_str());
for(int counter = 2; counter <= input; counter++)
{
for(int counter2 = 2; counter2 <=input && Prime == true; counter2++)
{
if(((counter%counter2)==0) & counter2!=1 & counter2!=counter)
{
Prime = false;
break;
}
else
{
cout << counter << endl;
}
}
}
cout << "Please Enter A Number Less Than 2: " << endl;
cin >> input;
}
return 0;
}
// the cout is there just for me to view my output instantly (my university uses Solaris)
but here are my problems
- Prime Numbers Duplicate Themselves A Number Of Times
- Multiple's of 5 exist
- cannot use functions or classes

New Topic/Question
Reply




MultiQuote



|