i have most of the program done, but id like to take out the pointers and change my readdata function into something simpler. Thank You!^
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void readdata(int &, int*&, int*&);
void printarr(int, int[]);
int smallest(int, int[]);
void construct(int, int[], int[], int *&);
void whatshigher(int[], int[], int, int &, int &, int &);
ofstream logFile;
int main()
{
int n = 0;
int *score1 = new int[];
int *score2 = new int[];
int *scoresum = new int[];
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
logFile.open("C:/Log.txt");
readdata(n, score1, score2);
logFile<<"There are " <<n<<" values in each array"<<endl;
logFile<<"Score1 array: ";
printarr(n, score1);
logFile<<"Score2 array: ";
printarr(n, score2);
logFile<<endl;
logFile<<"The smallest value in scores1 is: "<<smallest(n, score1)<<endl;
logFile<<"The smallest value in scores2 is: "<<smallest(n, score2)<<endl<<endl;
logFile<<"The scoresum array: ";
construct(n, score1, score2, scoresum);
logFile<<"The smallest value in scoresum is: "<<smallest(n, scoresum)<<endl<<endl;
whatshigher(score1, score2, n, counter1, counter2, counter3);
logFile<<"Scores1 was larger "<<counter1<<" times"<<endl;
logFile<<"Scores2 was larger "<<counter2<<" times"<<endl;
logFile<<"The two scores were equal "<<counter3<<" times"<<endl;
logFile.close();
return 0;
}
void readdata(int &n, int *&arr1, int *&arr2)
{
ifstream file;
string fileName = "C:/Scores.txt";
string line;
string score1;
string score2;
int count = 0;
file.open(fileName);
if(file.is_open()){
std::getline(file, line);
n = stoi(line);
arr1 = new int[n-1];
arr2 = new int[n-1];
while(std::getline(file, score1, ' ')){
std::getline(file, score2, '\n');
arr1[count] = stoi(score1);
arr2[count] = stoi(score2);
count++;
}
}
file.close();
return;
}
void printarr(int num, int vals[])
{
for(int i = 0; i < num; ++i)
{
logFile<< vals[i] << " ";
}
logFile<<endl;
return;
}
int smallest(int lim, int nums[])
{
int lowest = nums[0];
for(int i = 1; i < lim; ++i)
{
if(nums[i] < lowest)
{
lowest = nums[i];
}
}
return lowest;
}
void construct(int k, int first[], int second[], int *&sumarr)
{
sumarr = new int[k-1];
for(int i = 0; i < k; ++i)
{
sumarr[i] = first[i] + second[i];
}
printarr(k, sumarr);
return;
}
void whatshigher(int first[], int second[], int n, int &counter1, int &counter2, int &counter3)
{
for(int i = 0; i < n; ++i)
{
if(first[i] > second[i])
{
logFile<<"In position "<<i<<", array score1 is larger: "<< first[i] << " is greater than " << second[i]<<endl;
counter1++;
}
else if(first[i] < second[i])
{
logFile<<"In position "<<i<<", array score2 is larger: "<< second[i] << " is greater than " << first[i]<<endl;
counter2++;
}
else
{
logFile<<"In position "<<i<<", the two arrays have the same value: " << first[i]<<endl;
counter3++;
}
}
logFile<<endl;
return;
}