//Hello QtC,
//I'm having more trouble with this problem than I expected, if anyone can suggest some fixes it would be greatly appreciated!
//This program should read numbers from one file, determine if they are prime or not, then output the numbers into a SECOND file
//that show the input Numbers, the Quotients of inputs divided by 5(with precision 2), Prime numbers, and the Not Prime numbers in an array:
//I use Visual Studio 2013
#include <iostream>
#include <fstream>
using namespace std;
//function prototypes:
bool determinePrime(int num); //determines if the number is prime (true) or not (false)
void printOutput(int a[], int size); //shows the result to user
void div5Quotient(); //calculates the quotient by dividing input by 5
//opens new file (prog_outputs) and writes in results
// ofile.open("prog_outputs.txt ;
// //array width
// for (!filenameIN.eof()){
// cin >> arr[w]
// w++
// out<< SETw[15]<<ARR[x]<<"."
//out.sef(IOS:showpoint);
//OUT.Precision(2);
//}
int main()
{
int count = 0;
int a[11];//size of the array, more than the 10 entries in data file
int b = 0;
int divisor;
int c; //array for values/5
int x=5;
ifstream infile;
// 1. Input
infile.open("prog_inputs.txt");//open the text file
if (!infile.is_open())
{
cout << "Unable to open file! ";
exit(1); // if file didn't open
}
while (!infile.eof()) //reads from the file until the end
{
//To make array for column---reading from the file into x
//the updated array will have elements for every input
infile >> a[count];
count++;
}
// cout <<a[i]<<endl;
// Process our data
// print our data
printOutput(a, count);
}
//2. To determine if number is prime:
bool determinePrime(int num){
// check for NOT prime
for (int i = 2; i < num; i++)
{
if (num % i == 0)
{
return false;
}
}
// if check completes, means it is a prime
return true;
}
//shows the results as an array to user
void printOutput(int a[], int size) {
for (int i = 0; i < size; i++)
{
if (determinePrime(a[i]))
{
cout << a[i] << "\t" << "Prime" << endl;
}
else
{
cout << a[i] << "\t" << "Not Prime" << endl;
}
}
double div5Quotient() {
a/x;
//OUT.Precision(2);
}
}
//Prime number check function works fine but I can't simply divide the values by 5, or output to a new file
Bookmarks