writing files

I am new to this and need some help. This program is suspose to write the assignment name, points possible, and grade in a file. Then it is suspose to display it. Later on I will need to be able to access the file so I can change some of the details but I don't know how to do that either.


#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int numberGrades;
char itemDescription[50];
int points[100];
int score[100];


bool writeFile()
{
ofstream output;
output.open("grades.txt", ios::app);
if (output.fail())
return false;

output << "4\n";
output << "Assign1 " << " 200 " << " 95\n"
<< "Assign2 " << " 100 " << " 80\n"
<< "Project " << " 100 " << " -1\n"
<< "Midterm " << " 100 " << " -1\n";
if (output.fail())
{
output.close();
return false;
}

output.close();
return true;
}


bool readFile()
{
int num;
ifstream input;
input.open("grades.txt");
if (input.fail())
return false;

int count = 0;
for (count = 0; count < num && input.eof(); count++)
input >> numberGrades;
input >> itemDescription[count] >> points[count] >> score[count];

cout << numberGrades << endl;
cout << itemDescription[0] << " " << points[0] << " "
<< score[0] << endl;
cout << itemDescription[1] << " " << points[1] << " "
<< score[1] << endl;
cout << itemDescription[2] << " " << points[2] << " "
<< score[2] << endl;
cout << itemDescription[3] << " " << points[3] << " "
<< score[3] << endl;

exit(1);

input.close();
return true;
}


int main()
{
writeFile();
readFile();
return 0;
}

Please edit your post and put code tags around the code.
Check the for loop
Why do you have exit(1) in readFile?
closed account (S6k9GNh0)
He probably thinks it does something else.
Topic archived. No new replies allowed.