I'm getting errors that don't make any sense.

I'm trying to do my homework, but I can't understand the errors that I'm getting. By looking at the examples in my book, everything is perfect, but it doesn't want to compile. Can anyone tell me what's wrong?


In function `int range(int, int)':
34 assignment of function `int range(int, int)'
34 cannot convert `int' to `int ()(int, int)' in assignment
35 invalid conversion from `int (*)(int, int)' to `int'
In function `int main()':
83 invalid conversion from `int (*)()' to `int'
83 initializing argument 1 of `int range(int, int)'

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
    
int n;
int numbers[99];

int minimum()
{
    int minimum;
    minimum = numbers[0];
 return minimum;
}

int maximum()
{
  int maximum;
  maximum = numbers[98];
  return maximum;
}

int median()
{
    int median = numbers[47];
    return median;
}


int range(int maxx,int minn)
{
    range = maxx - minn;
    return range;
}

float mean()
{
    int mean;
    int c;
    int a;
    for (a = 1;a <= 98;a++)
    {
        c = a - 1;
        mean = numbers[a] + numbers[c];
    }
    mean /= 98;
  return mean;
}

int main()
{
    int i;
    ifstream fin;
    
    fin.open("numbers.txt");
    if (!fin.good()) throw "I/O error";
    

    fin >> n;
    fin >> numbers[98];
    fin.ignore(1000, 10);

    for (i = 0; i < n; i++)
    {
        int j;
        for (j =i + 1; j < n; j++)
        {
            if (numbers[i] > numbers[j])
            {
                int temp = numbers[i];
                numbers[i] = numbers[j];
                numbers[j] = temp;
            }
        }
     }

    fin.close();
    minimum();
    maximum();
    median();
    range(maximum, minimum);
    mean();
    

    system("PAUSE");
    return 0;
}
Last edited on
Line 32
1
2
3
4
5
int range(int maxx,int minn)
{
    range = maxx - minn; // 'range' is the name of the function change name and add the type (int)
    return range;
}

Line 80: minimum(); The name of the function is 'min'
Line 83: range(maximum, minimum); // same error for 'min' and you are missing the ()
LOL newbies. You still haven't seen template compiler errors or linker errors. You can only use your intuition to fix those, because reading them won't help much. Some of them can easily reach 1000 characters in length.

Also, that's one shitty book.
Wow I feel like an idiot now, I always have some stupid little syntax error. Thanks

Now I'm getting

In function `int main()':
83 invalid conversion from `int (*)()' to `int'
83 initializing argument 1 of `int range(int, int)'
In function `int main()':
83 invalid conversion from `int (*)()' to `int'
83 initializing argument 2 of `int range(int, int)'

What does it mean, by conversion?

P.S. Yeah, this book sucks, but it was written by the head of the department so we have to use it. It teaches double in the fist 20 pages, but doesn't teach float until after functions.
Last edited on
maximum and minimum (without the parentheses) are pointers to maximum() and minimum(). If you want a function to be called, you have to put the parentheses, otherwise, you're just getting the pointer: range(maximum(), minimum());
I think that is an old standard, though. IINM, in the new standard referring to a function without its parentheses just evaluates to true, rather than getting the function pointer.
Hey, that worked helios. I thought that I could just use the returned value from maximum and minimum rather than running the function again. Oh well, thanks for all your help.
Topic archived. No new replies allowed.