invalid conversion error

Hey guys. I'm having trouble when it comes to sorting my array in ascending order. When i build my code it tells me "error: invalid conversion from int to int" in lines 102 and 103 which I'm guessing refers to whats in void sortArray and void showArray. I don't understand the error and don't know how to fix it. I'm new to coding so any help will be appreciated.


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
107
108

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


void sortArray( int array[], int size)
{
    bool swap;
    int temp;

    do
    {
        swap = false;
        for (int count = 0; count < (size - 1); count ++)
        {
            if(array[count] > array[count + 1])
            {
                temp = array[count];
                array[count] = array[count + 1];
                array[count + 1] = temp;
                swap = true;
            }
        }
    } while (swap);
}

void showArray( int array[], int size)
{
    for(int count = 0; count < size; count++)
    {
        count++;
        cout << array[count] << " ";
            if (count % 10 == 0)
            {
                cout << endl;
            }
    }
}


int main ()
{
    ifstream dataIn;
    int numbers, c = 0;
    double array[50], total = 0.0, average, highest, lowest;


    dataIn.open("arrays.txt");
    if (!dataIn)
        cout << "Error. Try again.\n";
    else
    {
        for (numbers = 0; numbers < 50; numbers++)
            dataIn >> array[numbers];
        dataIn.close();

        for (numbers = 0; numbers < 50; numbers++)
            total += array[numbers];

        average = total / 50;

        highest = lowest = array[0];
        for (numbers = 1; numbers < 50; numbers++)
        {
            if (array[numbers] > highest)
                highest = array[numbers];
            else if (array[numbers] < lowest)
                lowest = array[numbers];

        }

        cout << fixed << showpoint << setprecision(2);
        cout << "Total = " << total << endl;
        cout << "Average = " << average << endl;
        cout << "Highest = " << highest << endl;
        cout << "Lowest = " << lowest << endl;


        for (numbers = 0; numbers <= 50; numbers++)
        {
            c++;
            cout << array[numbers] << " ";
            if (c % 10 == 0)
            {
                cout << endl;
            }
        }
        cout << endl;

        for (numbers = 50; numbers >= 0; numbers--)
        {
            c++;
            cout << array[numbers] << " ";
            if (c % 10 == 0)
            {
                cout << endl;
            }
        }

        sortArray(numbers, 50);
        showArray(numbers, 50);

    }
    return 0;
}
Last edited on
well you are passing "numbers" which is just a int instead of a array in lines 102, 103 , you should pass the array because thats what you specified in your function
Last edited on
@leryss

its not letting me pass the array because it will give me an error such as "cannot covert double to int for argument '1' to void sortArray' and same thing when i switch them to ints or doubles. I tried passing array[], array[numbers], array[50] but they don't seem to work.
The problem is that sortArray and showArray expect int arrays but you pass only an int to them in main.
1
2
3
4
    
int numbers    
sortArray(numbers, 50);
showArray(numbers, 50)


In main you have a double array - maybe you want to sort and show this ???
@thomas1965

i tried everything even declaring array[50] as an int.

i also tried this

1
2
sortArray (array[numbers], 50)
showArray (array[numbers], 50)


and also tried
1
2
soertArray (array[50], 50)
showArray (array[50], 50)


really appreciate the help but I'm going nowhere with these tips.
If you have an array of int called array then you call your functions like this.
1
2
3
4
int array[50];

sortArray (array, 50)
showArray (array, 50)
closed account (48bpfSEw)
http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.