Can you help find bug?

I have to do this program, with more, in my class... I was wondering if anyone can help me find the actual bug, I have two error messages, which I will comment after to show which lines they are appearing on.
*EDIT* I would like to smooth out the program as well, edits in bold current working problems underlined
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
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int bubbleSort(const int nameofArray[], int incrementingList[], int arraySize);
int getMin(int test, int currentMin);

int main()
{
        const int size = 5;
	int x[size] = {5,4,6,1,8};
	int y[size];

	cout << x[size] << endl; //warning C4700: uninitialized local variable 'x' used
// (It was noted that I am initiallizing x[5] without that being
// a value, I'm looking to put an array here.)
	y[size] = bubbleSort(x, y, size);
	return 0;
		
	
	

}
int bubbleSort(const int nameofArray[], int incrementingList[], int arraySize)
//fixed line above (23) - error C2143: syntax error : missing ')' before ';'
// fixed still line above (23) - error C2059: syntax error : ')'
{ // fixed error C2470: 'arraySize' : looks like a function definition, , but there is no parameter list;
	int smallestNumber = 10;
	int placeHolder= 0;
	int test = 0;
	for (int i = 0;i < arraySize-1 ; i++)
	{
		test = nameofArray[i];
		smallestNumber = getMin(test, smallestNumber);
		incrementingList[i] = smallestNumber;
	}
	cout << incrementingList[arraySize] << endl ;
         return incrementingList[arraySize];

}
int getMin(int test, int currentMin )
{
	if(currentMin < test)
		currentMin = test;
	return currentMin;

}


It might be because I've been staring at the code, but I don't think there should be any extra parenthesis in the line with the errors... Thanks in advance for any help! I haven't been able to run the program at all, so I don't even know if it works or not. Any advice would be great.
Last edited on
You've got terminators (;) instead of commas (,) in the parameters of your function definition.

EDIT: Also, the function prototype specifies a const int array, the function declaration specifies an int array for the first parameter. This might bite you.
Last edited on
Thanks that was quick! I didn't even see that the semicolons were wrong haha. After those edits (switching to commas and labeling my protype as a const int array) I am gettting this error on line 32 - error C2065: 'nameOfArray' : undeclared identifier
I thought nameOfArray is identified by the function?
One has a captial 'O' in the 'of' part, the other doesn't.

You need to make sure the function parameters match the references in the function.
HAHAHAHA. Thank you so much. I cannot believe it. :D So simple.
So the new error is that x is not being initiallized. Showing at line 15
It usually is. :-)
Last edited on
I've been answering the errors accordingly, but it seems as soon as I fix one error, another bout of errors come up hehe.
All part of the fun. ;-)
Looking at my bubbleSort function, it doesn't seem to make sense. Do you think you could help me make it work? I think I have part but not all of what I need.
int x[size] = {5,4,6,1,8};

x[0] = 5
x[1] = 4
x[2] = 6
x[3] = 1
x[4] = 8

you are then trying to cout << x[5] when there is no value in x[5]
I'm not very good at this yet, and so I'm wondering how do I cout the entire array, if not by cout << x[size]?
I'm no expert either, but I guess this would work.
1
2
3
4
5
6
int n = 0;
while (n != size)
{
   cout << x[n] << " ";
   n++;
}
Last edited on
Thanks for your help, iHutch and Jadax, I'm going to mark as 'solved' because the initial problem was solved, I might put a new topic up, if I run into too many more problems. Still looking for a good way for bubbleSort, because as it works now, running through it in my head, it doesn't look like it will actually sort.
Topic archived. No new replies allowed.