I suck at C++! like really badly, i just cant grasp it, and now i have to write a program for it that is suppose to input some values from a text file that would create like a gradebook thing. im also supposta use a void function, calculatedAverage to determine the average of the five test scores and use a loop to read and sum the first five test scores. Then a value returning function calculatedGrade to determine each students grade in the main function. this is the stuff from the txt file thst needs to be read

StudentData.txt
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

and it needs to be outputted looking like a table. i have made numerouse ttempts at makeig this, and i am not getting any help from any of my teachers, they say i must lear i on my own, but i rally am haveing a hard time. this is what i have so far:

#include <iostream>
#include <string>
using namespace std;

void calculateAverage(ifstream& inF, ofstream& outF, double& CAvg);

int main()
{
	cout << " Student            Test1    Test2    Test3    Test4    Test5    Average    Grade" << endl;
}

void calculateAverage(ifstream& inF, ofstream& outF, double& CAvg)
{
	std::ifstream in("StudentData.txt",std::ios::in |std::ios::binary);
	return 0;
}

as you can see i rally suck, it wont even compile! please someone help, i have to have this done asap! please!

P.S. i also attached the .txt file and the .cpp file please someone help im desperate at this point, ive been working on it for 3 days now!

It doesn't compile because it is missing the header file <fstream>

it sill won compile even after adding <fstream>
the compiler says:
------ Build started: Project: assignment 5, Configuration: Debug Win32 ------
Compiling...
assignment 5.cpp
c:\users\charles\cs122\assignment 5\assignment 5\assignment 5.cpp(16) : error C2562: 'calculateAverage' : 'void' function returning a value
c:\users\charles\cs122\assignment 5\assignment 5\assignment 5.cpp(6) : see declaration of 'calculateAverage'
Build log was saved at "file://c:\Users\Charles\CS122\assignment 5\assignment 5\Debug\BuildLog.htm"
assignment 5 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

still working on it but have made very little progress, still cant compile

Look at the line number in the error message then look in your code at that line. That error means that you declared calculateAverage to be a void function, which does not have a return value. Delete line 15 of the code you posted because it is causing that error.

OK Great i did that now all i need is for it to display the stuff in the text file then add up their grades and do the sum thing. i was hoping that i had that part but once it was compiled all it did was display the cout stuff

i gave up at about 1am cause i have work today, but i am still trying to get this this thing done, i must have it done soon any further help would be apreciated. all i need if for it to read the values from a text file and put them into a table that looks like a gradebook, then calculate their grades. please someone help, I REALLY SUCK A C++!

Post your code so that we can make suggestions.

>>I REALLY SUCK A C++!
Shhhhhh -- don't tell anyone but I think I do too :)

here is my code so far. all it dose is compile and print out the cout statement

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

void calculateAverage(ifstream& inF, ofstream& outF, double& CAvg);

int main()
{
	cout << " Student         Test1    Test2    Test3    Test4    Test5    Average    Grade" << endl;
}

void calculateAverage(ifstream& inF, ofstream& outF, double& CAvg)
{
	std::ifstream in("StudentData.txt",std::ios::in |std::ios::binary);
	  ofstream myfile ("StudentData.txt");
  if (myfile.is_open())
  {
        myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}

}

You have to declare three variables in main() and call calculateAverage().

how do i do that?

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.