Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 10-09-2005, 06:34 PM   #1 (permalink)
Cro
Registered User
 
Join Date: Oct 2005
Posts: 5
OS: XP


Help with C++...functions.

hi guys... well basically this is the code i have: It retreives information from a text file>.... this txt file looks like:

Balto 85 83 77 91 76 -999
Mickey 80 90 95 93 48 -999
Minnie 78 81 11 90 73 -999
Doc 92 83 30 69 87 -999
Goofy 23 45 96 38 59 -999
Duckey 60 85 45 39 67 -999
Grumpy 27 31 52 74 83 -999
Sunny 93 94 89 77 97 -999
Piggy 79 85 28 93 82 -999
Pluto 85 72 49 75 63 -999

Now if you run the following code... it displays everything like i would like it to...but im having trouble displaying the "grades" column... for example... if the "average" for a student is more then 90...he would ge an A.. if its between 80-90 - B and so on... i just cannot get to display it... i need to use a function (calculateGrade) and it needs to return the grade.. i also cannot use global variables. :( please if someone could help>...

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

void calculateAverage(ifstream& inp, int score1, int score2, int score3, int score4, int score5, double& courseAvg, double& classAvg);
//char calculateGrade(char grade, double avg2);

int main()
{
	cout << setprecision(1);
	cout << fixed << showpoint;

	int score1;
	int score2;
	int score3;
	int score4;
	int score5;
	string name;
	//double grade;
	int numberOfStudents;
	double avg;
	char grade;
	char final;
    double avg2;
	int sum = 0;
	double classAvg;


	
	

	ifstream infile;
	
	infile.open("C:\\Documents and Settings\\Magas\\Desktop\\SCHOOL\\C++Assign2\\TestScores.txt");
	

	if(!infile)
	{
		cout << "Cannot open the input file." << endl;
		cout << "Program will terminate!" << endl;
		return 0;
	}

	numberOfStudents = 0;

	cout << "Student" << "   " << "Test1" << "   " << "Test2" << "   " << "Test3" << "   " << "Test4" << "   " << "Test5" << "   " << "Average" << "   " << "Grade";
	cout << endl;

	infile >> name >> score1 >> score2 >> score3 >> score4 >> score5;
	
	while(infile)
	{

		//Calls the "calculateAverage" function to calculate the averages
		calculateAverage(infile, score1, score2, score3, score4, score5, avg, classAvg);

		//Calls the "calculateGrade" function to calculate the final letter grades
		//calculateGrade(final, avg);

		cout << setfill(' ') << left << setw(12) << name << setw(8) << score1 << setw(8) << score2 << setw(8) << score3 << setw(8) << score4 << setw(8) << score5 << setw(8) << avg/5 << setw(8) << final;
		
		cout << endl;
		

		infile >> name >> score1 >> score2 >> score3 >> score4 >> score5;


		}
	
	cout << endl << endl;
	cout << "Class Average = " << (classAvg/5)/10 << endl << endl;
}



void calculateAverage(ifstream& inp, int score1, int score2, int score3, int score4, int score5, double& courseAvg, double& classAvg)
{
	int score;
	inp >> score;
	while(score != -999)
	{	
		inp >> score;
		
	}

	courseAvg = (score1 + score2 + score3 + score4 + score5);
	classAvg = (classAvg + courseAvg);
	
}
Cro is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-10-2005, 12:05 AM   #2 (permalink)
Cro
Registered User
 
Join Date: Oct 2005
Posts: 5
OS: XP


NVM guys...! :) i think i got it... thanks anyways
Cro is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 01:43 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85