ARRAYS

What is wrong in this code please help!!

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
#include <iostream>
#include <ctime>
using namespace std;

void FillOddArray(int a[], int size);
void OutputArray(int a[], int size);
void LargeSmall(int a[], int& largest, int& smallest, int size);


int main()
{
	srand((unsigned)time(NULL));

	int ar[40];
	int largest, smallest;

	FillOddArray(ar, 40);
	LargeSmall(ar, largest, smallest, 40);
	OutputArray(ar, 40);


	cout << "The smallest number in the array is " << smallest << " and the largest is "
		<< largest << endl;
	return 0;
}
void FillOddArray(int a[], int size)
{


	const int sizeOfArray = sizeof(a) / sizeof(*a); 
		int rn = rand() % 1000 + 1;
	for (int n{ 0 }; n != sizeOfArray; n++)
	{
		for (int n = 0; n < size; n++)
		{
			do
			{
				rn = rand() % 1000 + 1;
				if (rn % 2 != 0)
				{
					a[n] = rn;
				}
				else
				{
					rn = rand() % 1000 + 1;
				}
			} while (rn % 2 == 0);
		}
	}
}
void OutputArray(int a[], int size)
{
	const int sizeOfArray = sizeof(a) / sizeof(*a);
		for (int i = 0; i < size; i++)
		{
			cout << a[i] << '\t';
		}
	cout << endl;
}
void LargeSmall(int a[], int& largest, int& smallest, int size) 
{
	int less = 1;
	int more = 0;

	const int sizeOfArray = sizeof(a) / sizeof(*a);
	int ab[sizeOfArray];
	for (int n{ 0 }; n != sizeOfArray; n++)
		largest = smallest = a[0];
	for (int n = 1; n < size; n++)
	{
		ab[n] = a[n];
		if (a[n] < smallest)
		{
			smallest = a[n];
		}
		else if (a[n] > largest)
		{
			largest = a[n];
		}
	}

	for (int b{ 0 }; b != sizeOfArray; b++)
	{
		for (int c{ 0 }; c != (sizeOfArray - 1); c++)
		{
			if (ab[c] > ab[c + 1])
			{
				int temp = ab[c];
				ab[c] = ab[c + 1];
				ab[c + 1] = b;
			}
		}
	}
	int largestNumber = a[sizeOfArray - 1];
	int smallestNumber = a[0];
	if (largest == more)
	{
		return largestNumber;
	}
	else
	{
		return smallestNumber;
	}
}
Last edited on
What makes you think there is something wrong with that code?

Please use code tags when posting code!

In my last function it says void cannot out put a value which makes sense but if i will put 'int' it will not give me an answer!!
Topic archived. No new replies allowed.