Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

c++ i need help less than an hour.. can't figure it out


  • Please log in to reply

#1
Glenda Ruth Hayes

Glenda Ruth Hayes

    New Member

  • Member
  • Pip
  • 4 posts
#include <iostream>
#include <fstream>
using namespace std;

//this program is going to output the student id and gpa in accending order
//function prototype
void sortArray(float,int);

int main()
{
const int SIZE= 100; //Array size
int id[SIZE];
int GPA;
int j;

ifstream inputFile;
char dataFile[20];

inputFile.open("dataFile.txt");

char fileName[20];
cout<<" The file name is GPA.txt";
ofstream outputFile;
outputFile.open("GPA.txt");
cout<<id<<endl;
cout<<GPA<<endl;
for(j = 0; j< SIZE; j++)
{
cout<<"please enter the student id number"<<endl;
cin>>id[j];
cout<<"please enter the gpa. "<<endl;
while(GPA!=99)
{
cout<<"please enter the gpa. ";
cin>>GPA;
cout<<GPA;
}
sortArray(GPA, SIZE);
inputFile.close();
outputFile.close();
system("pause");
return 0;
}

}
void sortArray (float array[],int SIZE)

{

bool swap;
float GPA;

do
{
swap=false;
for(count=0; count>(SIZE-1); count++)
{
if(array[SIZE]> array[SIZE + 1])
{
GPA=array[SIZE];
array[SIZE]=array[SIZE + 1];
array[SIZE + 1] = GPA;
swap = true;
}
}
} while (swap);

cout<<GPA<<endl;
}
}
}

errors are
_____________________

In function `void sortArray(float*, int)':
: error: overloaded function with no contextual type information
: error: invalid operands of types `<unknown type>' and `int' to binary `operator>'
error: no post-increment operator for type
At global scope:
error: expected declaration before '}' token

Execution terminated
  • 0

Advertisements


#2
Glenda Ruth Hayes

Glenda Ruth Hayes

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
70 C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp expected declaration before '}' token

down to that error
  • 0

#3
Nathan

Nathan

    Member

  • Member
  • PipPipPip
  • 691 posts
It looked like you had two extra }'s. You're also using a while statement with nothing..

I suggest you go read this: http://www.learncpp....ile-statements/

P.S. I'm not the best with C++ but I think this may be it.
  • 0

#4
Glenda Ruth Hayes

Glenda Ruth Hayes

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
it does have a statement. idk what it could be looks like im going to fail it oh well i will talk to my teacher
  • 0

#5
Nathan

Nathan

    Member

  • Member
  • PipPipPip
  • 691 posts
void sortArray(float,int);

Try using:
void sortArray(float [],int);

  • 0

#6
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,355 posts
Hey man,

Don't know if this is what you looking for, I have reviewed your code and just fixed things up abit as not to produce any errors. Even if it's not ,maybe you can adjust it making it do what you want. I have left comments next to all the code I have changed that caused error and given it a very basic description of why it should be like it is. Hopefully it'll also help make you realize where it is you went wrong and fix it in any later versions.

Edit: Also changed your GPA to an array where ever necessary

#include <iostream>
#include <fstream>
#include <cstdlib> // You were missing this library (need for using "system()")

using namespace std;

//this program is going to output the student id and gpa in accending order
//function prototype
void sortArray(float[],int);

int main()
{
    const int SIZE= 3; //Array size
    int id[SIZE];
    float GPA[SIZE]; // Need to make an array since you sending through an array in your sortArry function, it must also be a float type to match the function header
    int j;

    ifstream inputFile;
    char dataFile[20];

    inputFile.open("dataFile.txt");

    char fileName[20];
    cout<<" The file name is GPA.txt";
    ofstream outputFile;
    outputFile.open("GPA.txt");
    cout<<id<<endl;
    cout<<GPA<<endl;

    for(j = 0; j< SIZE; j++)
    {
        cout<<"please enter the student id number"<<endl;
        cin>>id[j];
        cout<<"please enter the gpa. "<<endl;

        while(GPA[j]!=SIZE - 1) // Should set this or it'll cotinue until your old specified 99
        {
            cout<<"please enter the gpa. ";
            cin>> GPA[j]; // Must store it some where in the array of GPA
            cout<<GPA[j];
        }

        sortArray(GPA, SIZE);
        inputFile.close();
        outputFile.close();
        system("pause");
        return 0;
    }
}

void sortArray (float array[],int SIZE)
{

    bool swap;
    float GPA;

    do
    {
        swap=false;
        for(int count=0; count>(SIZE-1); count++) // You have to declate count type (as integer)
        {
            if(array[SIZE]> array[SIZE + 1])
            {
                GPA=array[SIZE];
                array[SIZE]=array[SIZE + 1];
                array[SIZE + 1] = GPA;
                swap = true;
            }
        }
    }
    while (swap);

    cout<<GPA<<endl;
}

Peace Out Posted Image

Edited by spike_hacker_inc, 30 March 2012 - 04:17 PM.

  • 0

#7
Glenda Ruth Hayes

Glenda Ruth Hayes

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
thanks on the array size thats what my teacher told me to put it as. so it has to be 100 lol and i had to set it to stop at 99.9 that was teh sentail value. lol but everything else makes since. lol i knew it was something that i kept over looking. to bad i got a zero on it now. lol for it not compiling that day
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP