due at 4pm texas time.

#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[SIZE];
int j;
ifstream inputFile;
char GPA.txt[20];

inputFile.open(dataFile);
ofstream outputFile;
outputFile.open("GPA.txt");
char fileName[20];
cout<<" The file name is GPA.txt";
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;
inputFile.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] = temp;
swap = true;
}
}
} while (swap);
)

}
cout<<GPA<<endl;
}



the errors are saying


C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp: In function `int main()':
C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp:15: error: expected primary-expression before "char"
C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp:15: error: expected `;' before "char"

C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp:17: error: `dataFile' undeclared (first use this function)
C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp:17: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Users\Glenda hayes\Documents\c++ programing labs\lab6.cpp:22: error: request for member `txt' in `GPA', which is of non-class type `int[100]'

error: ISO C++ forbids comparison between pointer and integer
error: no match for 'operator>>' in 'std::cin >> GPA'
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:87: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:93: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:102: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:111: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:133: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]

C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:164: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:186: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:217: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:239: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:261: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:284: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:306: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:329: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:351: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:373: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:395: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/bits/istream.tcc:417: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/istream:646: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&) [with _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/istream:651: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&) [with _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/istream:687: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*) [with _Traits = std::char_traits<char>]
C:/Dev-Cpp/include/c++/3.4.2/istream:692: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*) [with _Traits = std::char_traits<char>]
error: a function-definition is not allowed here before '{' token
error: expected `,' or `;' before '{' token
error: invalid conversion from `int*' to `int'
warning: address of local variable `GPA' returned
error: expected `}' at end of input
Okay... let's see...

First of all, the only characters that you can have in a variable name are anything in the US alphabet and digits. Periods aren't allowed. Sorry.

On line 17, you're using a variable you've never declared.

You're opening your stream three times, the last of which is with a variable that was never set to anything.

std::cin and std::cout don't know how to read to/from arrays of integers. Why are you declaring GPA as an array, even?

That should get you started. :)

-Albatross

Upload your Lab6.cpp and Lab6.txt file, and your GPA data file. I will also use my own data file to test your program. This lab uses parallel arrays and sorting techniques. Read in 4 digit student numbers and gpa scores from a data file into two parallel arrays. You should prompt the user and use a cin statement to read the file name into a char variable (char dataFile[20];), then use that char variable in your open statement (inputFile.open(dataFile);). The file will be a text file and the format will be student number on one line and GPA on the next line.
Set the array size to 100, but read in and store values into your array only until the value of 99.9 for GPA is read. (Hint, don't use == for float values, check for GPA >99). 99.9 is the sentinal value in the file.
Once you have populated the array, sort the arrays in ascending order by GPA score and print the results to the screen.
The format for your input file should be something like this:
1111
3.2
1222
1.8
1333
4.0
0000
99.9

this is why... i am trying to get it to work like this and this is why i have the 99 in there.
Topic archived. No new replies allowed.