Need help with array sorting

I need some help with my first Programming lab, I have an idea of what the issues are, I know most of them occur with my bubble sort in the sortedArray function.

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
#include "stdafx.h"
#include <iostream> //cin and cout
using namespace std;

main() {
	double grades[20]; //array
	int numGrades;
    
	numGrades = Grades(grades);
}


int Grades(double grades[]) //gathers user input into array
{
	int x; //number of grades
	cout << "how many grades are there?";
	cin >> x;
	for (int i = 0; i < x; i += 1) {
		cout << "Please input the grade # " << i+1 ;
		cin >> grades[i];
	}

	//collects user input and stores it into an array (up to 20)
	return x; //returns number of grades
}
void sortedArray(Grades()) //sorts the array
{
	bool swap;
	int temp;
	

	do {
		swap = false;
			for (int count = 0; count < (Grades() - 1); count++) //need x from Grades
			{
				if (grades[count] > grades[count + 1])
				{
					temp = grades[count];
					grades[count] = grades[count + 1];
					grades[count + 1] = temp;
					swap = true;
				}
			}
	} while (swap);
}
int median() //returns the median of the array
{
	double median;
	if (Grades % 2 = 0) {
		median = ((Grades[x / 2] + Grades[x / 2 + 1]) / 2);
	}
	else
	{
		median = Grades[x / 2];
	}
	return median;
}
What problems are you having? Is it sorting in reverse order? Is it sending random colored pages to your print queue? Is it cancelling your appointments? You need to be specific.

Line 5: main must return int

Line 26: That isn't how you declare a function. Look at line 13 to see how you did it before.

What happens if there are more than 20 grades?

Your grades are doubles but your median function returns an integer. (Also, your median function doesn't have access to the grades array in the first place).
Last edited on
Topic archived. No new replies allowed.