Calling function

My program is supposed to ask for 4 numbers and i will cout the numbers as
x|x|x|x. Poblem is the compiler wont call my function. Any ideas?
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
#include <iostream>
#include <string>

using namespace std;

const int row = 4;

int board[row];

double complete(int board[])
{
    int newBoard;
    int i;
    
    for (i = 0; i < row; i++)
    {
        cin >> board[i];
        cout << board[i] << " | " << endl;
        newBoard += board[i];
    }
    
    return newBoard;
}

int main()
{
    int num;
    
    do
    {
    cout << "enter numbers in row" <<endl;
    cin >> num;
    }while(num < 4);
    
    cout << complete(num);
    
    system("pause");
    return 0;
}
Last edited on
Line 12: newBoard is not initialized (to 0). It will have an arbitrary number.

Line 35: You're not passing the array but a single number.

Instead of
1
2
3
4
5
6
7
    do
    {
    cout << "enter numbers in row" <<endl;
    cin >> num;
    }while(num < 4);
    
    cout << complete(num);
it should look like this:
1
2
3
4
5
6
7
    cout << "enter numbers in row" <<endl;
    for(int i = 0; i < 4; i++)
    {
    cin >> board[i];
    }
    
    cout << complete(board);
or
1
2
3
4
5
6
7
    for(int i = 0; i < 4; i++)
    {
    cout << "enter number " << i + 1 << endl;
    cin >> board[i];
    }
    
    cout << complete(board);
Im getting an error "unutilized variable newBoard unused"
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
#include <iostream>
#include <string>

using namespace std;

const int row = 4;

int board[row];

int complete(int board[])
{
	int newBoard;

	for (int i = 0; i < row; i++)
	{
		newBoard += board[i];
		cout << newBoard << " | " << endl;
		
	}

	return 0;
}

int main()
{

	for (int i = 0; i < row; i++)
	{
		cout << "enter numbers in row" << i + 1 << endl;
		cin >> board[i];
	}


	cout << complete(board);

	system("pause");
	return 0;
}
Yes:
line 12: int newBoard = 0;
line 21: return newBoard;
Topic archived. No new replies allowed.