bubbleSort

We got an error C2664: 'BubbleSort' : cannot convert parameter 1 from 'int' to 'int []. Please help. This is the code.




//Program Highest GPA

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

#include "myStack.h"

using namespace std;

void BubbleSort(int GPA[], int highestGPA)
{
int stack = highestGPA -1;


while (stack > 0);
{
int nextEnd = 0;

for (int j = 0; j < (stack - 1); ++j)
{
if (GPA[j] > GPA[j+1])
{
GPA[j] = GPA[j+1];
nextEnd = j;
}
else
++j;
}

stack = nextEnd;
}
}

int main()
{
//Step 1
double GPA;
double highestGPA;
string name;

stackType<string> stack(100);
ifstream infile;

infile.open("HighestGPAData.txt"); //Step 2

if(!infile) //Step 3
{
cout<<"The input file does not exist. "
<<"Program terminates!"<<endl;
return 1;
}

cout<<fixed<<showpoint; //Step 4
cout<<setprecision(2); //Step 4

infile>>GPA>>name; //Step 5

highestGPA = GPA; //Step 6


while(infile) //Step 7
{
cout << BubbleSort((int) GPA, (int) highestGPA) << endl;
//infile>>GPA>>name; //Step 7.3
}

cout<<"Highest GPA = "<<highestGPA<<endl; //Step 8
cout<<"The students holding the highest GPA are:"
<<endl;

while(!stack.isEmptyStack()) //Step 9
{
name = stack.top();
stack.pop();
cout<<name<<endl;
}

cout<<endl;

return 0;
}
Please use the code format tags to format your code. You can edit the post and apply the tags. Code is impossible to read if it's not formatted correctly.

When the compiler encounters an error, it reports what it thinks is wrong and the file/line it thinks it happened on. If you post an error message, you need to post the full error. Most folk don't have the time to read you code looking for your error.
The function BubbleSort is expecting an array/pointer of ints. The argument you pass is a) an int (because it's casted by (int)) and b) a single value (because you read in a single double).

'double GPA' should be an array of doubles which are then copied to an array of integers to do the casting. Reading in will require more than a simple >> statement. (Hint: loop!)

Another thing: your BubbleSort won't sort. It will overwrite values, in a very strange way:
1
2
3
4
if (GPA[j] > GPA[j+1])
{
GPA[j] = GPA[j+1]; 
//... 

Read it aloud: If GPA[j] is larger than GPA[j+1], GPA[j] will be set to the value of GPA[j+1]. That means that after that branch, GPA[j] == GPA[j+1]. The original value of GPA[j] is lost, and you now have the value GPA[j+1] twice.
Topic archived. No new replies allowed.