some array issues

I'm having fun learning arrays on my own, but I've hit a wall!
My code is outputting the reverse order as -858993460
My code is outputting the smallest number as -8.58993e+008

What can I do!
Thanks!
-goldyn

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
 #include <iostream>
#include <stdlib.h>
using namespace std;

const int MAX_INTEGERS = 20; //Max numbers in array always constant

void fill_array(int a[], int size, int& number);
int findLargest(const int a[], int number);
void showLargest(const int a[], int number);
int findSmallest(const int a[], int number);
void showSmallest(const int a[], int number);

int main()
{
	if (system("CLS")) system("clear"); //clears garbage from screen

	int integers[MAX_INTEGERS], number;

	cout << "This program outputs an array backwards." << endl;
	cout << "This program also shows you the largest and smallest integer in the array." << endl;

	fill_array(integers, MAX_INTEGERS, number);
	showLargest(integers, number);
	showSmallest(integers, number);

	return 0;
}

void fill_array(int a[], int size, int& number)
{
	cout << "Enter up to " << size << " integers.\n"
		<< "Mark the end of the list with a 0.\n";
	int next, index = 0;
	cin >> next;
	while ((next != 0) && (index < size)) //prompts user for integers until 0 is input
	{
		a[index] = next;
		index++;
		cin >> next;
	}

	number = index;

	cout << "The reverse order is" << endl;
	for(int i = size-1; i > 0; --i);
	{
		cout << a[size];
	}
	cout << endl;
}

int findLargest(const int a[], int number) //Function computes largest number
{
	for(int i=0;i<5;i++)
    {
        if(a[i]>number)//if number is smaller than array, larger number
        number=a[i];
    }
    
	return number;
}

void showLargest(const int a[], int number) //Function to display largest number to screen
{
	double largest = findLargest(a, number);
		cout << "The largest number in this list is: "<< largest << endl;
}

int findSmallest(const int a[], int number) //Function computes smallest number
{
	for(int i=0;i<5;i++)
    {
        if(a[i]<number)//if number is larger than array, smallest number
        number=a[i];
    }
    
	return number;
}

void showSmallest(const int a[], int number) //Function to display smallest number to screen
{
	double smallest = findSmallest(a, number);
		cout << "The smallest number in this list is: "<< smallest << endl;
}	
Few logic issues but other then that.

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
#include <iostream>
#include <stdlib.h>
#include <limits>

using namespace std;

const int MAX_INTEGERS = 20; //Max numbers in array always constant

void fill_array(int a[], int size, int& number);
void findLargest(const int a[], int number);
void findSmallest(const int a[], int number);

int main()
{
	if (system("CLS")) system("clear"); //clears garbage from screen

	int integers[MAX_INTEGERS], number;

	cout << "This program outputs an array backwards." << endl;
	cout << "This program also shows you the largest and smallest integer in the array." << endl;

	fill_array(integers, MAX_INTEGERS, number);
	findLargest(integers, number);
	findSmallest(integers, number);


	return 0;
}

void fill_array(int a[], int size, int& number)
{
	cout << "Enter up to " << size << " integers.\n"
		<< "Mark the end of the list with a 0.\n";
	int next, index = 0;
	cin >> next;
	while ((next != 0) && (index < size)) //prompts user for integers until 0 is input
	{
		a[index] = next;
		index++;
		cin >> next;
	}

	number = index;

	cout << "The reverse order is" << endl;
	for (int i = number - 1; i >= 0; --i){
		cout << a[i];
	}
	cout << endl;
}

void findLargest(const int a[], int number) //Function computes largest number
{
	int num = numeric_limits<int>::min();
	for (int i = 0; i<number; i++)
	{
		if (a[i]>num)//if number is smaller than array, larger number
			num = a[i];
	}

	cout << "Largest is: " << num << endl;
}

void findSmallest(const int a[], int number) //Function computes smallest number
{
	int num = numeric_limits<int>::max();
	for (int i = 0; i<number; i++)
	{
		if (a[i] < num)//if number is larger than array, smallest number
			num = a[i];
	}

	cout << "Smallest is: " << num << endl;
}
I'm still getting an issue with my program outputting the reverse order, any idea why?
cout << "This program outputs an array backwards." << endl;

Isn't it supposed to?
Sorry lol, I should have clarified. It is outputting reverse correctly, but is there a way I can get it to output it this way:

I want to try and get it to

Array:
1
2
3
4
0

Reverse:
4
3
2
1

Thanks so much for all of your help!
Last edited on
Topic archived. No new replies allowed.