STUDENT AVERAGES PROGRAM

input data from a file to calculate the student's average and add

Page 1 of 1

7 Replies - 1580 Views - Last Post: 01 November 2009 - 09:30 PM Rate Topic: -----

#1 liteskin23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 09

STUDENT AVERAGES PROGRAM

Posted 21 October 2009 - 02:53 PM

here is what i have so far for some reason it will not compile it keeps going to int sum saying it is not declared can someone please help me im not asking you to do it for me i just need an extra pair of eyes to pick out what is wrong.

this is what is in my input file
Alphy Beta 85 83 77 91 76
Brant Baxter 80 90 95 93 48
Craig Cooper 78 81 11 90 73
Don Duck 92 83 30 69 87
Ellie Eggman 23 45 96 38 59
Frank Fritz 60 85 45 39 67
George Gomez 77 31 52 74 83
Harry Hacker 93 94 89 77 97
Hilda Hacker 79 85 28 93 82
Horatio Hacker 77 78 79 80 45
Izzie Ills 95 72 99 89 91
Jack Sprat 99 98 100 96 92
Klem Kluless 88 77 66 55 44
Lonny Luckster 68 68 68 68 68
Maude Mazel 90 88 86 84 90
Ned Nicholls 55 55 55 55 55



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

using namespace std ;
string message;
string studentName;
char courseGrade(int average);

int main ()
{
    ifstream inData; //input file stream variable
    string studentName; // student name from file
    int num1,num2,num3,num4,num5 // scores of students
    int sum,    // sum of scores for one student
    int highest// highest of the student scores
    int count, // number of tests for one student
    int score, // student score
    int average, // average for one student
    int studentnum, // number of students in class
    int classaverage;// average for the class
      
    
        
    inData.open ("Project3_Data3.txt");
    if (!inData)
    {
       cout << "input file not found \n";
       system ("pause");
       return 1;
    }
    
    
   
    while (inData)
    {
     inData >> studentName;
     cout << "Student Name:" << studentName << endl;
     inData >> scores;
     cout << "Scores:";
     
     while (score != -1)
     { 
       cout << score << " ";
       sum = (num1+num2+num3+num4+num5);
       sum = 0;
       count = 0;
       count++;
       inData >> score;
     }
       
     
     cout << "\n Your Average";
     average = sum/count;
     cout <<average;
    
    
     if ( average >= 90)
     cout << "\t A";
     else if (average >= 80)
     cout << "\t B";
     else (average >= 70)
     cout << "\t C";
     else if (average >= 60)
     cout << "\t D";
     else (average >= 59)
     cout << "\t F";
  
     
cout << "\n The number of students : " <<studentNum <<endl;

system ("pause");
     return 0;
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 21 October 2009 - 02:58 PM


Is This A Good Question/Topic? 0
  • +

Replies To: STUDENT AVERAGES PROGRAM

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: STUDENT AVERAGES PROGRAM

Posted 21 October 2009 - 03:06 PM

Put a semi-colon after each of these lines (before the comment):
int num1,num2,num3,num4,num5 // scores of students
    int sum,    // sum of scores for one student
    int highest// highest of the student scores
    int count, // number of tests for one student
    int score, // student score
    int average, // average for one student
    int studentnum, // number of students in class


Was This Post Helpful? 0
  • +
  • -

#3 liteskin23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 09

Re: STUDENT AVERAGES PROGRAM

Posted 25 October 2009 - 09:27 AM

I went back and did that and now when I went to compile and execute it came out but now its like one of my loops just keeps on going and I'm trying to double check my braces making sure each one has and open and close but can't find anything. lol

this is my new code with the corrections
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
string message;
char courseGrade(int average);
int main ()
{
    string name;
    
    int sum,
        count,
        score,
        average,
        studentnum,
        highest,
        lowest;
    
    ifstream inData;
    
    inData.open("Project3_Data3.txt");
    if (!inData)
    {
       cout <<"input file not found \n";
       system ("pause");
       return 1;
    }
    
    inData >> name;
    highest = 0;
    lowest = 100;
    studentnum = 0;
    while (inData)
    {
          cout << "Student Name:" << name << endl;
          sum = 0;
          count =0;
          inData >> score;
          cout << "Scores:";
          while (score != -1)
          { cout << score << " ";
            sum = (sum + score);
            count++;
            inData >> score;
          }
       
     average = sum / count;
     cout << "\nYour average after" <<count << "is:";
     cout << average;
     
     if (average >= 90)
     cout << "A." << endl;
     else if (average >= 80)
     cout << "B." << endl;
     else if (average >= 70)
     cout << "C." << endl;
     else if (average >= 60)
     cout << "D." << endl;
     else 
     cout  << "F." << endl;
     
     cout << "\n *************************\n";
     
     inData >> name;
     
     if (average>=highest)
         highest=average;
     if (lowest>=average)
         lowest=average;
     studentnum++;
     
   } 
   cout << "\nThe highest student average was: " <<highest;
   cout << "\nThe lowest student average was: " <<lowest;
   cout << "\nThe number of students processed were: " <<studentnum
   <<endl;
   
   system ("pause");
   return 0;
   }




####################################

View PostJackOfAllTrades, on 21 Oct, 2009 - 02:06 PM, said:

Put a semi-colon after each of these lines (before the comment):
int num1,num2,num3,num4,num5 // scores of students
    int sum,    // sum of scores for one student
    int highest// highest of the student scores
    int count, // number of tests for one student
    int score, // student score
    int average, // average for one student
    int studentnum, // number of students in class


This post has been edited by JackOfAllTrades: 25 October 2009 - 09:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: STUDENT AVERAGES PROGRAM

Posted 25 October 2009 - 09:38 AM

Hint: This line:
inData >> name;

is only reading the first name into name.
Was This Post Helpful? 0
  • +
  • -

#5 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: STUDENT AVERAGES PROGRAM

Posted 25 October 2009 - 10:21 AM

here's an example of how I just did it... You seemed to over complicate a lot of it. I just used 1 header file and array and had it work out just fine.

EDIT: Sorry, I didn't see the part about the input file. This takes command line inputs

#include <iostream>

using namespace std;

int NumOfScores;

int CalcAvg(int StudentScores[])
{
	int StudentScoresTotal;
	int StudentScoresAvg = 0;
	for (int counter = 0; counter <= NumOfScores - 1; counter++)
	{
		StudentScoresTotal = StudentScoresTotal + StudentScores[counter];
	}
	StudentScoresAvg = StudentScoresTotal / NumOfScores;
	return StudentScoresAvg;
}

int main()
{
	cout << "Enter the amount of scores: ";
	cin >> NumOfScores;
	int ScoreArray[NumOfScores - 1];
	for (int counter = 0; counter <= NumOfScores - 1; counter++)
		{
			cout << "Enter score #" << counter + 1 << ": ";
			cin >> ScoreArray[counter];
		}
	cout << "The average is " << CalcAvg(ScoreArray) << endl;
}


This post has been edited by Sn0wm4n: 25 October 2009 - 11:38 AM

Was This Post Helpful? 0
  • +
  • -

#6 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: STUDENT AVERAGES PROGRAM

Posted 25 October 2009 - 11:22 AM

EDIT: sorry wrong thread

This post has been edited by Sn0wm4n: 25 October 2009 - 11:24 AM

Was This Post Helpful? 0
  • +
  • -

#7 liteskin23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 09

Re: STUDENT AVERAGES PROGRAM

Posted 01 November 2009 - 09:29 PM

well thanks i got it to complie but it is not reading all of my names and scores
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
string message;
char courseGrade(int average);
int main ()
{

	string firstname;
	string lastname;
	int sum, // sum of scores for student
		count, // number of test for student
		t1,t2,t3,t4,t5, // test
		average, // average for student
		studentnum, // number of students
		highest, // highest score of student grade
		lowest; // lowest score of student grade
	
	ifstream inData; // input file stream variable

inData.open("Project3_Data3.txt");
	if (!inData)
	{
	   cout <<"input file not found \n";
	   system ("pause");
	   return 1;
	}
	
	inData >> firstname >>lastname;
	highest = 0;
	lowest = 0;
	studentnum = 0;
	
	while (inData)
	{
	  inData >> firstname >> lastname; 
	  cout << "\n\nStudent Name:"<<" "<< firstname<<" "<<lastname<<endl;
	  
	  sum = 0;
	  count = 4;
	  cout <<"Scores:";
	  inData >> scores;	   
		  while (scores!= 4)
		  { cout << scores << " ";
			sum = sum + scores;
			count++;
			inData >> scores;
			break;
			}
	   
	 average = sum /count;
	
	 cout << "\nYour average after" << count << "is";
	 cout << average; cout << "and the grade is:" << average;
	
	 if(average >= 90)
	 cout << "A." << endl;
	 else if (average >= 80)
	 cout << "B." << endl;
	 else if (average >= 70)
	 cout << "C." << endl;
	 else if (average >= 60)
	 cout << "D." << endl;
	 else 
	 cout << "F." << endl;
	 
	 cout << "*********************************************\n";
	 
	 inData >> firstname >> lastname;

	 
	 if (average>=highest)
		 highest=average;
	 if (lowest<=average)
		 average=lowest;
	 studentnum++;
	 
   } 
   cout << "\nThe highest student average was: " <<highest;
   cout << "\nThe lowest student average was: " <<lowest;
   cout << "\nThe number of students processed were: " <<studentnum
   <<endl;
   
   system ("pause");
   return 0;
   }



** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5187
  • View blog
  • Posts: 26,895
  • Joined: 10-May 07

Re: STUDENT AVERAGES PROGRAM

Posted 01 November 2009 - 09:30 PM

Please use code tags... Like this ---> :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1