Trouble with arrays

I am supposed to use arrays to create a program that removes the lowest number and highest number. Than it needs to add the rest but I can't even get my program to run.

The user needs to enter 8 scores:9.2,9.3,9.0,9.9,9.5,9.5,9.6,9.8.
the output should be:
contestant recieves: 56.90
Dropped low score: 9.00
Dropped High Score: 9.90




Any help to fix these errors will be appreciated. I'm not good at C++.
10 F:\Program6-Arrays2.0.cpp expected init-declarator before "int"
10 F:\Program6-Arrays2.0.cpp expected `,' or `;' before "int"
F:\Program6-Arrays2.0.cpp In function `void getinput(int*, int)':
33 F:\Program6-Arrays2.0.cpp `num' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
35 F:\Program6-Arrays2.0.cpp `counter' undeclared (first use this function)
38 F:\Program6-Arrays2.0.cpp `score' undeclared (first use this function)
39 F:\Program6-Arrays2.0.cpp `sum' undeclared (first use this function)
F:\Program6-Arrays2.0.cpp In function `int getlow(int*, int)':
49 F:\Program6-Arrays2.0.cpp `numbers' undeclared (first use this function)
50 F:\Program6-Arrays2.0.cpp `SIZE' undeclared (first use this function)
59 F:\Program6-Arrays2.0.cpp a function-definition is not allowed here before '{' token
59 F:\Program6-Arrays2.0.cpp expected `,' or `;' before '{' token
86 F:\Program6-Arrays2.0.cpp expected `}' at end of input


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<iostream>
#include<cmath>
#include<conio.h>
#include<iomanip> //needed for setw()

using namespace std;

// Function prototypes
int getlow(int[],int)
int gethigh(int[],int)
double getsum(int[],int)
void getinput(int[],int)
void showoutput(int[],int)

int main()
{
    int getlow,gethigh,numbers[SIZE];
    double getsum,scores;
    const int SIZE = 50;

void getinput(int[],int)
int getlow(int[],int)
int gethigh(int[],int)
double getsum(int[],int)
void showoutput(int[],int)
    
}

void getinput(int[],int)
{
     
cout << "Enter number of Judges Scores:";
cin >> num;

while (counter <= num )
{   
  cout << "Enter Judges Score #" <<counter << ":";
  cin >> score;
  sum+=score;
  counter++;
}
}

int getlow(int[],int limit)
{
    int  count;
    int lowest;
    
    lowest = numbers[0];
    for (count = 1; count < SIZE; count++)
    {
        if (numbers[count]<lowest)
           lowest = numbers[count];
}

    
    
int gethigh(int[],int)
{
    int count;
    int highest;
    
    highest=numbers[0];
    for(count=1;count<SIZE;count++)
{
    if(numbers[count]> highest)
    highest=numbers[count];
}

double getsum(int[],int)
{
       double scores;
       
       scores+=score
       scores-=lowest
       scores-=highest
}

void output[int[],int]
{
     cout<<setprecision(1)<<fixed<<showpoint;
     cout<<"Contestant Receives: "<<scores<<endl;
     cout<<"Dropped Low Score: "<<lowest<<endl;
     cout<<"Dropped High Score: "<<highest<<endl;
system("pause");
}


Last edited on
Missing semicolon after the function prototypes.
SIZE is used before it has been declared.
num, sum, counter and score are not declared.
In gethigh and getlow you try to access numbers but the numbers array you have in main is not reachable from other functions. You can either make numbers global or pass it as an argument.
Missing ending bracket for the function definition of gethigh and getlow
Definition of output are missing a pair of parenthesis
Last edited on
You may be making it a bit more complicated than it needs to be;
1) Use a loop to enter the elements (8 values) into an array
2) Use a loop to traverse the array and find the high and low values by assigning high and low to array[0]. if (array[1] > 'high') assign 'high' to array [1]. do similarly with 'low'. if(array[1]<'low') assign 'low' to array[1].
3)traverse the array again but ignore the high and low values by using 'continue' and an if(statement) such as if (array[i]=='high || array[i] == 'low') continue; otherwise sum the remaining elements with sum+=array[i].
4)print out the high,low and sum values
Thank you for all the input it has really helped.I have been working on it today and have minimalized my errors. Sadly, I still have a few errors left I can't figure out how to solve.
1
2
  28 F:\Program6-Arrays2.8.cpp cannot convert `double' to `double*' for argument `1' to `double getInput(double*, 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 #include<iostream>
#include<cmath>
#include<conio.h>
#include<iomanip> //needed for setw()

using namespace std;

// Function prototypes
double getInput(double[],int);
double getLow(double[],int);
double getHigh(double[],int);
double getsum(double[],int);


int main()
{
    const int SIZE=8;
    int num;
    double numbers;
    double sum;
    double lowestscore;
    double highestscore;
    double scores[SIZE];
    double array[0];

cout << setprecision(1) << fixed << showpoint;

sum= getInput(numbers,SIZE);

lowestscore = getLow (array,SIZE);

highestscore = getHigh (array,SIZE);

sum = getsum (array,SIZE);

sum -= lowestscore;

sum -= highestscore;
    

cout << "Contestant Receives: " << sum << endl;

cout << "Dropped Low Score: " << lowestscore << endl;

cout << "Dropped High Score: " << highestscore << endl;

return 0;
    
    
}

double getInput(double numbers[],int size)
{
     int index;
     
     for(index = 0; index <= size - 1;index++)
     {
 
  cout << "Enter Judges Score #" << (index+1) << ":";
  cin >> numbers[index];
}
}

double getLow(double array[], int size)
{
       double lowest;
       int counter=1;
       lowest = array[0];
       
for(int counter = 1; counter < size ; counter++)
{
        if( array [counter] < lowest)
            lowest = array [counter];

return lowest;
}

    
    
double getHigh( double array[] , int size);
{
    double highest;
    
    highest = array[0];
    for(int counter = 1; counter < size ; counter++)
{
    if(array [counter] > highest)
    highest = array [counter];
    
    return highest;
}

double getsum(double array[],int size);
{
       double sum=0;
       for(int count = 0 ;count < size ;count++)
       sum += array [count];

       
       return sum;
}
}
}
 
Last edited on
Line 55: you are referring to 'numbers' as an array... but the declaration at line 47 has 'numbers' as just a plain int. Perhaps the "int numbers" in line 47 should be "double numbers[]", and similarly line 23 should pass scores instead?

Line 77: you should declare counter locally, in the same way you declared count locally in line 87.
Last edited on
Thanks, I always seem to make the stupidest mistakes. Would you happen to know what I have to fix when I get this error: 28 F:\Program6-Arrays2.8.cpp cannot convert `double' to `double*' for argument `1' to `double getInput(double*, int)' ?
would I need to static_cast?
@bwilson1: nope, no need for static_cast.

The purpose of line 28 is to get some input, right? how is that input returned?

(sorry, going to make you think now ;-)...).

(also, I suspect you might end up with a warning, if not an error, associated with the getInput() routine at line 52... because it does not actually 'return' anything...).
Topic archived. No new replies allowed.