confusing errors!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nyx18
    New Member
    • Feb 2008
    • 5

    confusing errors!

    ok so i got my class to work now im having confusing errors with this:
    Code:
    void sort(Student stu[], int parameter, int count)
    {
       Student temp;
    	
       bool finished = false;
       while (!finished)
       {
          finished = true;
          for (int i = 0; i< count-1; i++)
          {
    [79]       if(Student[i].compareTo(Student[i+1], parameter) == true)
    [80]       {
    	temp = stu[i];
    	stu[i] = stu[i+1];
    	stu[i+1] = temp;
    	finished = false;
                 }
         }
      }
    }
    the errors are
    1>h:\cs 215\program 2\program 2\program 2.cpp(79) : error C2059: syntax error : '['
    1>h:\cs 215\program 2\program 2\program 2.cpp(80) : error C2143: syntax error : missing ';' before '{'

    i dont know what the problem with my synatx could be.

    and my compareTo function is:
    Code:
    bool Student::compareTo (Student stu2, int parameter)
    {
    	if (parameter ==1)
    	{
    		if(FirstName < stu2.FirstName)
    			return false;
    		else 
    			return true;
    	}
    	if (parameter ==2)
    	{
    		if(LastName < stu2.LastName)
    			return false;
    		else 
    			return true;
    	}
    	if (parameter ==3)
    	{
    		if(GPA < stu2.GPA)
    			return false;
    		else
    			return true;
    	}
    	if (parameter ==4)
    	{
    		if(age < stu2.age)
    			return false;
    		else
    		    return true;
    	}
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Hi,
    [code=cpp]
    //if(Student[i].compareTo(Stud ent[i+1], parameter) == true)
    //Why are u using Vraiable type to access a variable.
    //it is like specifying int[i];

    //You should use the variable name instead of variable type

    //it should be
    stu[i].compareTo(stu[i+1], parameter) == true)
    {
    }
    [/code]

    Raghuram

    Comment

    Working...