I have been getting used to c++ as I have been trying various scenarious on programs and exand on them with new concepts. This is my first try at exporting data from command line to a text file and the program runs fine with all the calculations. The real issue is that none of the outputs are exported to the text file. It is probably some simple oversight and want to say thanks in advance for helping me. Note- This program is supposed to take the inputs of a teacher and export the individual grade w/ letter the number of assignments and class average with letter to the text file.
#include <iostream>
#include <cmath>
#include <cfloat>
#include <fstream>
int i;
float testScore[100];
float sum = 0;
float clavg;
char grade;
int main()
{
std::fstream myfile;
myfile.open("grades.txt"); //name of file
std::cout<<"Please Enter Your Students Grades."<<std::endl;
std::cout<<"Type 999 to get Avg"<<std::endl;
for (i=0; i<100; i++)
{
std::cin>>testScore[i];
if(testScore[i] == 999)
{
break;
}
if (testScore[i] >= 90 && testScore[i]<=100)
{
grade = 'A';
}
if (testScore[i] >= 80 && testScore[i]<=89)
{
grade = 'B';
}
if (testScore[i] >= 70 && testScore[i]<=79)
{
grade = 'C';
}
if (testScore[i] >= 60 && testScore[i]<=69)
{
grade = 'D';
}
if (testScore[i] >=0 && testScore[i]<=59)
{
grade = 'F';
}
sum+=testScore[i];
myfile<<testScore[i]<<" "<<grade<<std::endl;
}
clavg = (sum/i);
if (clavg >= 90 && clavg<=100)
{
grade = 'A';
}
if (clavg>= 80 && clavg<=89)
{
grade = 'B';
}
if (clavg >= 70 && clavg<=79)
{
grade = 'C';
}
if (clavg>= 60 && clavg<=69)
{
grade = 'D';
}
if (clavg >=0 && clavg<=59)
{
grade = 'F';
}
myfile<<"Total Number of Assignments = "<<i<<std::endl;
myfile<<"Find Grade = "<<clavg<<" "<<grade<<std::endl;
myfile.close();
system("pause");
}