C++ Greatest Number Verification
- by Daniel
Hey guys, I was assigned to create a program that creates n arrays composed by 10 random integers. The the program should sum all the integers and display the result. After, it has to verify which of the sums is the greatest and it has to display that array and the result. Im having troubles getting it done and would like to get some help!
Thanks once again.
Here is my code so far:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double random(unsigned int &seed);
unsigned int seed = 5;
void generateData(int set[10]);
int sumData(int set[10]);
void checkData(int sumResult, int arrayNumber);
int main (int argc, char * const argv[])
{
int arrayNumber, sumResult;
int set[10];
do
{
cout << "Number of Arrays to Compare: " << endl;
cin >> arrayNumber;
} while (arrayNumber < 0);
for (int i = 0; i < arrayNumber; ++i)
{
generateData(set);
sumResult = sumData(set);
cout << "Sum --> " << sumResult << endl;
checkData(sumResult, arrayNumber);
}
return 0;
}
double random(unsigned int &seed)
{
const int MODULUS = 15749;
const int MULTIPLIER = 69069;
const int INCREMENT = 1;
seed = ((MULTIPLIER * seed) + INCREMENT) % MODULUS;
return double(seed) / double(MODULUS);
}
void generateData(int set[10])
{
for (int i = 0; i < 10; ++i)
{
set[i] = int (5 + 6 * random(seed));
cout << set[i] << " || ";
}
}
int sumData(int set[10])
{
int sumTotal = 0;
for (int i = 0; i < 10; ++i)
sumTotal = sumTotal + set[i];
return sumTotal;
}
void checkData(int sumResult, int arrayNumber)
{
int largerNumber;
int tempSet[2];
for (int i = 0; i < arrayNumber; ++i)
{
if (sumResult > largerNumber)
{
tempSet[i] = sumResult;
}
}
}