User defined arrays

I'm trying to write a C++ program that reads user values into two arrays, the user however first enters the number of integers to be read. The program then performs some equations for the sums, differences, products, and quotients for the two arrays corresponding values. I'm not really stuck on the math, but I don't understand how a user is defining the array parameters for two arrays and then entering integers for both.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*This program reads in two sets of integers from user, 
then computes and prints the sums, differences, and quotients
for corresponding values in the two arrays*/

using namespace std;

const int size = 1000;

#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <fstream>

void input (int data[size], int values);
void do_sums (int a [size], int b [size], int s [size], int values);
void do_differences (int a [size], int b [size], int d [size], int values);
void do_products (int a [size], int b [size], int p [size], int values);
void do_quotients (int a [size], int b [size], int q [size], int values);
void print (int a [size], int b [size], int answer [size], char op, int values);
int sum_of_all (int data1 [size], int data2 [size], int values);


no idea what to do in main, nor do I know if the user is defining the number of data values in main or in the definition. I also feel like I'm missing the parameters for the two arrays since there is only the void input parameter.

my main questions i suppose are: How do I allow the user to define a parameter for the arrays and how does that value get translated into the rest of the program since there is already a constant? And what would the code look like to allow the user to enter values for the first array, then the second array so the output looks something like this:
Enter the number of data values: (user input. . .3 for example)

Enter first set of array data:
Enter value 1 : (UserInput)
Enter value 2 : (UI)
Enter value 3 : (UI)

Enter second set of data:
Enter value 1: (UI)
Enter value 2: (UI)
Enter value 3: (UI) 
Dynamic allocation.

However, the details are gory, so here is a sugar-coated version:
1
2
3
4
5
6
7
8
9
10
size_t N {0};
std::cin >> N;
std::vector<T> array;
array.reserve( N );
T value;
size_t item {0};
while ( item < N && std::cin >> value ) {
  array.push_back( value );
  ++item;
}


On the other hand, all your functions take 'values'. Let the main read a number. Check that number<=size. If yes, you can call all your functions with it. (If no, report error and quit program.) It does not matter that all the arrays are a bit larger than required, because all your functions will operate on the specified range.
Thanks. Yeah the answer, 'values', was right in front of me. Program runs perfectly =]
Topic archived. No new replies allowed.