This is the code that is suppose to compute the class's average and standard diviation from a file which contains a collection of student ids and corresponding scores from my computer class and assign each student a letter grade. the class can have no less than 7 students and no more than 25 student

I need help with aeraging the grades

#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>

struct mike
{
int id;
float average = 0;
char lettergrade[1];
int numgrade;
int total = 0;
}hope;

void main()
{
ifstream MyData;
MyData.open("getdata.dat");
ofstream PutData;
PutData.open("putdata");

if(MyData.fail())
 {
        cout << "\n\nFile not successfully opened\n\n";
 }
cout << "\n\nFile Successfully opened\n\n";

int i=0;

do{
MyData >> hope.id >> hope.numgrade;

cout << hope.id << "\t" << hope.numgrade << "\t" << hope.lettergrade << "\t" << hope.average;

hope.total = hope.total + hope.numgrade;
hope.average = hope.average/hope.total;

if (hope.numgrade >= 90) strcpy(hope.lettergrade,"A");
else if (hope.numgrade >= 80) strcpy(hope.lettergrade,"B");
else if (hope.numgrade >= 70) strcpy(hope.lettergrade,"C");
else if (hope.numgrade >= 60) strcpy(hope.lettergrade,"D");
else strcpy(hope.lettergrade,"F");


PutData << "\n\n\n    Class Grades";
PutData << "\n";
PutData << "               Student ID: " << hope.id << endl;
PutData << "      Student Numbergrade: " << hope.numgrade << endl;
PutData << "      Student Lettergrade: " << hope.lettergrade << endl;
PutData << setiosflags(ios::fixed)
        << setiosflags(ios::showpoint)
        << setprecision(2);
PutData << "            Class Average: " << hope.average << endl;
}while(i>7 && i<25);

MyData.close();
PutData.close();
}

Try changing the first few lines of your code to:

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <iomanip>

using std::ifstream; using std::ofstream;
using std::cout; using std::endl;
using std::setiosflags; using std::ios; using std::setprecision;

struct mike
{
int id;
float average;
char lettergrade[1];
int numgrade;
int total;
}hope;

int main()
...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.