hey guys, i have a question, heres my program and what i need to do.
http://www.sci.brooklyn.cuny.edu/~jones/cisc1110/a5f12.pdf <----what i need to do
i have errors while trying to run this program on stuff not being declared, but i dont know how and where to declare it, can some1 help me please? its a really fast 5 mins top question. its urgent, i have a test on this program and i need to fix this program asap, ty!!^
#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 &);
ifstream infile5;
ofstream logFile;
int main()
{
int n = 0;
infile5.open("Scores.txt");
logFile.open("Log.txt");
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
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[])
{
infile5 >> n;
for(int i=0;i < n;i++)
{
infile5 >> arr1[i];
infile5 >> arr2[i];
}
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;
}