New to Functions()

I'm not really sure if this is how you use functions. There are errors saying "too many arguments to function 'int OutArray'"

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<iomanip>
#include<math.h>
#include<fstream>
#include<string>
#include<limits>
using namespace std;
int OneDimArray[10];
int AvgStdDev()
{
	int i;
	float NewAverage;
	float NewSoSD;
	int NewSum;
	float NewStandDev;
	int Number = 10;
	float ValidRangesN;
	float ValidRangesP;
	float SoSD;
	int Sum;
	float Average;
	float StandDev;
	for (int i = 0; i< 10; i++)
	{
		Sum = Sum + OneDimArray[i];
	}
	Average = Sum / 10;
	for (i = 0; i <  10; i++)
	{
		SoSD = SoSD + pow((OneDimArray[i] - Average), 2);
	}
	StandDev = sqrt(SoSD / 10);
	ValidRangesN = Average - (StandDev + 4);
	ValidRangesP = Average + StandDev + 4;
	for (i = 0; i < 10; i++)
	{
		if ((OneDimArray[i] < ValidRangesN) || (OneDimArray[i] > ValidRangesP))
		{
			cout<<"This number will be dropped: "<<OneDimArray[i]<<endl;
			OneDimArray[i] = 0;
			Number = Number - 1;
		}
		else
		{
			continue;
		}
	}
	if (Number < 10)
	{
		for (i = 0; i< 10; i++)
		{
			NewSum = NewSum + OneDimArray[i];
		}
	NewAverage = NewSum / Number;
		for (i = 0; i < 10; i++)
		{
			NewSoSD = NewSoSD + pow((OneDimArray[i] - NewAverage), 2);
		}
	NewStandDev = sqrt(NewSoSD / Number);
	cout<<"Average of 10 Numbers: "<<NewAverage<<endl;
	cout<<"Standard Deviation: "<<NewStandDev<<endl;
	}
	else
	{
	cout<<"Average of 10 Numbers: "<<Average<<endl;
	cout<<"Standard Deviation: "<<StandDev<<endl;
	}
}
int OutArray()
{
	for (int i = 0; i < 10; i++)
	{
		cout<<"Array ["<<i+1<<"]: "<<OneDimArray[i]<<endl;
		AvgStdDev(OneDimArray[i]);
	}
}
int InArray()
{
	for (int i = 0; i < 10; i++)
	{
		cout<<"\nEnter 10 numbers ["<<i+1<<"]: ";
		cin>>OneDimArray[i];
		OutArray(OneDimArray[i]);
	}
}
int main()
{
	int OneDimArray[10];
	InArray(OneDimArray[10]);
	return 0;
}
int OutArray() has NO arguments. if it did, it would look like
int OutArray(int x)

but you call it like this:

OutArray(OneDimArray[i]); which has a parameter that you did not define for it.

either call it

outarray();
or add the parameter and use it somehow in the code.
Last edited on
It now has the error "invalid conversion from 'int' to 'int*' [-fpermissive]
what did you change?

I changed OutArray(); to OutArray(OneDimArray[i]);
InArray(); to InArray(OneDimArray[i]);
AvgStdDev(); to AvgStdDev(OneDimArray[i]);
This version compiles. I haven't touch the part where it performs calculation, so I'm quite sure I haven't damaged anything, but please check 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <cmath>
#include <iostream>
#include <limits>

constexpr int ARR_SIZE = 10;

int* InArray(int* OneDimArray, size_t size);
int* OutArray(int* OneDimArray, size_t size);
void AvgStdDev(int* OneDimArray, size_t size);
void waitForEnter();

int main()
{
    int OneDimArray[ARR_SIZE] {};
    InArray(OneDimArray, ARR_SIZE);
    waitForEnter();
    return 0;
}

int* InArray(int* OneDimArray, size_t size)
{
    for (size_t i = 0; i < size; i++)
    {
        std::cout << "\nEnter " << size << " numbers [" << i+1 << "]: ";
        std::cin >> OneDimArray[i];
        std::cin.ignore(1);
    }
    OutArray(OneDimArray, size);
    return OneDimArray;
}

int* OutArray(int* OneDimArray, size_t size)
{
    for (size_t i = 0; i < size; i++)
    {
        std::cout << "Array [" << i+1 << "]: " << OneDimArray[i] << '\n';
    }
    AvgStdDev(OneDimArray, size);
    return OneDimArray;
}

void AvgStdDev(int* OneDimArray, size_t size)
{
    int Sum = 0;
    for (size_t i = 0; i < size; i++) 
    {
        Sum += OneDimArray[i];
    }
    double Average = Sum / size;
    
    double SoSD = 0;
    for (size_t i = 0; i < size; i++)
    {
        SoSD += pow((OneDimArray[i] - Average), 2);
    }

    double StandDev = sqrt(SoSD / size);
    double ValidRangesN = Average - (StandDev + 4);
    double ValidRangesP = Average + StandDev + 4;

    size_t Number = size;
    for (size_t i = 0; i < size; i++)
    {
        if ((OneDimArray[i] < ValidRangesN) || (OneDimArray[i] > ValidRangesP))
        {
            std::cout << "This number will be dropped: " << OneDimArray[i] << '\n';
            OneDimArray[i] = 0;
            Number -= 1;
        }
        else
        {
            continue;
        }
    }

    int NewSum = 0;
    double NewAverage = 0.0,
           NewSoSD = 0.0,
           NewStandDev = 0.0;
    if (Number < size)
    {
        for (size_t i = 0; i< size; i++)
        {
            NewSum = NewSum + OneDimArray[i];
        }
        NewAverage = NewSum / Number;
        for (size_t i = 0; i < size; i++)
        {
            NewSoSD = NewSoSD + pow((OneDimArray[i] - NewAverage), 2);
        }
        NewStandDev = sqrt(NewSoSD / Number);
        std::cout << "Average of " << size << " numbers: " << NewAverage << '\n';
        std::cout << "Standard Deviation: " << NewStandDev << '\n';
    }
    else
    {
        std::cout << "Average of " << size << " numbers: " << Average << '\n';
        std::cout << "Standard Deviation: " << StandDev << '\n';
    }
}

void waitForEnter()
{
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

Last edited on
that looks correct so far. Let us know if you run into any other issues.

vectors have size built in, so you don't have to pass size for those and are usually preferred over arrays for this and other reasons. But that isn't an error, just something to consider.

Thanks for the help guys.
Topic archived. No new replies allowed.