Anyone know how to fix these errors.

Hello, I finished typing in a code for a bubble sort for an array. I keep getting errors saying "definition of i is ignored" and "definition of i is used". Not sure what to do to fix this. Also, if any other errors are found in my code, please tell me so I can fix it. Thanks.

Here's my code:


#include <iostream>
#include <string>
#include<conio.h>
using namespace std;


int temp;

void reverseEven(int my_array2[], int i)
{
for (int i = 0; i < 5; i++)
for (j = 0; j<(5 - i); ++j)
if (my_array2[j]>my_array2[j + 1])
{
temp = my_array2[j];
my_array2[j] = my_array2[j + 1];
my_array2[j + 1] = temp;
}

cout << "Array after bubble sort: ";
for (i = 0; i<5; ++i)
cout << my_array2[i] << " ";
getch();
}

int main()
{
int my_array2[5] = { 23, 4, 8, 12, 3 };
reverseEven(my_array2, 5);
system("Pause");
return 0;
}
You pass i as a parameter and then you create a new variable called i instead of the loop. Maybe rename the parameter? Though your second loop doesn't declare a new variable int so that one would then be undefined.
You don't have an open { or an end } for your two for loops.
Topic archived. No new replies allowed.