Apr 3, 2017 at 4:52pm Apr 3, 2017 at 4:52pm UTC
Hello, the problem is that i cant deal with initialization of 2 - n array.
1) It there a way to have input const variable by user?
2) What is wrong with my program? It should allow user to input numbers, then output it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "stdafx.h"
#include <iostream>
using namespace std;
void InputGroups(int (**setOfGroups[4][5]), int groups, int numbersIn);
void OutputGroups(int (**setOfGroups[4][5]), int groups, int numbersIn);
int main()
{
unsigned const int groups = 4;
unsigned const int numbersIn = 5;
int **setOfGroups[groups][numbersIn] = {0};
InputGroups(**setOfGroups[4][5], groups, numbersIn);
OutputGroups(**setOfGroups[4][5], groups, numbersIn)
return 0;
}
void InputGroups(int (*setOfGroups[4][5]), int groups, int numbersIn)
{
for (int i = 0; i <= groups; i++)
{
for (int k = 0; k <= numbersIn; k++)
{
cin >> (*setOfGroups)[i][k];
}
}
}
void OutputGroups(int *setOfGroups[4][5], int groups, int numbersIn)
{
for (int i = 0; i <= groups; i++)
{
cout << "" << endl;
for (int k = 0; k <= numbersIn; k++)
{
cout << (*setOfGroups[i][k]) << " " ;
}
}
}
Last edited on Apr 3, 2017 at 4:54pm Apr 3, 2017 at 4:54pm UTC
Apr 3, 2017 at 5:22pm Apr 3, 2017 at 5:22pm UTC
Anyway it does not work without any pointers :(
(14 line) error C2664: 'void InputGroups(int [][5],int,int)': cannot convert argument 1 from 'int' to 'int [][5]'
(15 line) error C2664: 'void OutputGroups(int [][5],int,int)': cannot convert argument 1 from 'int' to 'int [][5]'
Last edited on Apr 3, 2017 at 5:30pm Apr 3, 2017 at 5:30pm UTC
Apr 3, 2017 at 5:32pm Apr 3, 2017 at 5:32pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "stdafx.h"
#include <iostream>
using namespace std;
void InputGroups(int setOfGroups[4][5], int groups, int numbersIn);
void OutputGroups(int setOfGroups[4][5], int groups, int numbersIn);
int main()
{
unsigned const int groups = 4;
unsigned const int numbersIn = 5;
int setOfGroups[groups][numbersIn] = {0};
InputGroups(setOfGroups[4][5], groups, numbersIn);
OutputGroups(setOfGroups[4][5], groups, numbersIn);
return 0;
}
void InputGroups(int setOfGroups[4][5], int groups, int numbersIn)
{
for (int i = 0; i <= groups; i++)
{
for (int k = 0; k <= numbersIn; k++)
{
cin >> setOfGroups[i][k];
}
}
}
void OutputGroups(int setOfGroups[4][5], int groups, int numbersIn)
{
for (int i = 0; i <= groups; i++)
{
cout << "" << endl;
for (int k = 0; k <= numbersIn; k++)
{
cout << setOfGroups[i][k] << " " ;
}
}
}
Last edited on Apr 3, 2017 at 5:33pm Apr 3, 2017 at 5:33pm UTC
Apr 3, 2017 at 5:37pm Apr 3, 2017 at 5:37pm UTC
You didn't remove the array size information from your function calls as shown in my first post. All you need is the name of the array in your function call.
Apr 3, 2017 at 6:05pm Apr 3, 2017 at 6:05pm UTC
Do you understand the difference between a function call and a function implementation?
You need to remove the array size information in the function call, lines 14 and 15. (see the second snippet in my first post).
The function implementations (lines 20 and 31) require the size information. Please re-read my first post. The function implementations should look the same as the function prototypes (minus the trailing semicolon of course).