Input students score

This is a discussion on Input students score within the C++ Programming forums, part of the General Programming Boards category; But how can it determine whether the student is day or evening because I am reading from the 2 text ...

  1. #16
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    But how can it determine whether the student is day or evening because I am reading from the 2 text files?

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Which lines of code read from the file containing evening students?

  3. #18
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    This line for day: inFileDay
    This line for evening: inFileEvening

    Code:
    inFileDay.open("studentsDay.txt"); 
      inFileEvening.open("studentsEvening.txt");
      outFile.open("report_regular.txt");
    That is why I am having trouble for displaying the D or E for students because there are 2 text files as they will be output to report_regular.txt

  4. #19
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    No, those lines open the files. Which lines read from the file containing evening students.

  5. #20
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    ifstream inFileEvening? So how does this line let me put D or E.

  6. #21
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    whenever you're reading the information from inFileEvening, put an E in the file... I see you're having problems with the logic, so here's how your code should look:
    Code:
    //loop 1 - read in from inFileEvening
        //do the calculations
        outFile << surname <<' '<< givenname <<' '<< 'E' <<' '<< average << endl;
    //loop 2 - read in from inFileDay
        //do the calculations
        outFile << surname <<' '<< givenname <<' '<< 'D' <<' '<< average << endl;
    //close all the files and you're done
    ...of course that's after you've opened all the files and declared all the variables...
    Last edited by major_small; 04-28-2005 at 06:00 PM. Reason: colors...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #22
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    Thankx, so do I declare the D or E as char so it is for example:
    Code:
    char de

  8. #23
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by wiz23
    Thankx, so do I declare the D or E as char so it is for example:
    Code:
    char de
    ...or you could just output them directly as I did...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #24
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    I now need to find out the maximum and minimum average score from the student in both day and evening from the text files. I have done these but I think is wrong:
    Code:
    while (max==Average)
         {
         (count = 1; count <6; count++)
         max = larger(max,Average);
         }
         outFile<<studentdayId<<"  ";
         outFile<<surname<<", ";
         outFile<<givenname<<" ";
         outFile << max<<endl; 
         outFile<<"D ";
         outFile<<Average<<"  ";
    
    while (min==Average)
         {
         (count = 1; count <6; count++)
         min = smaller(min,Average);
         }
         outFile<<studentdayId<<"  ";
         outFile<<surname<<", ";
         outFile<<givenname<<" ";
         outFile << min<<endl; 
         outFile<<"D ";
         outFile<<Average<<"  ";

  10. #25
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    while (max==Average)
     {
    	 (count = 1; count <6; count++)
    	 max = larger(max,Average);
     }
    1) The statements inside the the while loop will only execute if max is equal to Average, so testing which is larger doesn't do anything--they are the same.

    Code:
    while (max==Average)
     {
    	 (count = 1; count <6; count++)
    	 max = larger(max,Average);
     }
    2)That's not a legal C++ statment.

    Code:
    while (max==Average)
     {
    	 (count = 1; count <6; count++)
    	 max = larger(max,Average);
     }
    3) Did you define a larger() function somewhere?

  11. #26
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    Do you mean declaring larger(max, Average)? I declare them as double for larger, max, Average.

  12. #27
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48

    Maximum and Minimum score

    I am trying to find the maximum and minimum average score from the student in both day and evening from the text files.
    Now I want to find the maximum average from day then find the maximum from evening and then compare both to see which is larger. Is this the right approach? I does this code for finding the maximum and minimum from day but once I complie and run it didn't show anything:

    Code:
    while (!inFileDay.eof() )
        {
         int score1, score2, score3, score4, score5;
         int studentcounter;
         double AverageDay, AverageEvening, largest = 0;
    
         inFileDay>>score1>>score2>>score3>>score4>>score5;
         AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
         studentcounter++;
         {
          while (studentcounter<=23)
          {
                ++studentcounter;
                if (AverageDay > largest)
                AverageDay = largest;
                }
                outFile<<AverageDay<<endl;
                }
    } 
    
    while (!inFileEvening.eof() )
        {
         inFileEvening>>score1>>score2>>score3>>score4>>score5;
         AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
         studentcounter++;
         {
          while (studentcounter<=23)
          {
                ++studentcounter;
                if (AverageEvening > largest)
                AverageEvening = largest;
                }
                outFile<<AverageEvening<<endl;
                }
    }
    
     if (AverageDay > AverageEvening)
    {
    outFile << AverageDay <<endl;
    else
    outFile << AverageEvening <<endl;
    }

  13. #28
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by wiz23
    Do you mean declaring larger(max, Average)? I declare them as double for larger, max, Average.
    ...do you really even know any C/C++? or any programming language at all?

    you're using larger as a function (or a subroutine in other languages), which has to be defined before you can use it... for example, your code should look something like this:
    Code:
    double larger(double max,double Average);
    
    int main()
    {
        ...
        max=larger(max,Average);
        ...
    }
    
    double larger(double max,double Average)
    {
        return (max>Average?max:Average);
    }
    and yes, I did give you the algoritm to get your average... just to show you that you don't need to do that in a function...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #29
    T-Mac wiz23's Avatar
    Join Date
    Apr 2005
    Location
    Houston
    Posts
    48
    Can somebody check this code as I need to output the maximum and minimum average score:

    Code:
    while (!inFileDay.eof() )
        {
         int score1, score2, score3, score4, score5;
         int studentcounter;
         double AverageDay, AverageEvening, largest = 0;
    
         inFileDay>>score1>>score2>>score3>>score4>>score5;
         AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
         studentcounter++;
         {
          while (studentcounter<=23)
          {
                ++studentcounter;
                if (AverageDay > largest)
                AverageDay = largest;
                }
                outFile<<AverageDay<<endl;
                }
    } 
    
    while (!inFileEvening.eof() )
        {
         inFileEvening>>score1>>score2>>score3>>score4>>score5;
         AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
         studentcounter++;
         {
          while (studentcounter<=23)
          {
                ++studentcounter;
                if (AverageEvening > largest)
                AverageEvening = largest;
                }
                outFile<<AverageEvening<<endl;
                }
    }
    
     if (AverageDay > AverageEvening)
    {
    outFile << AverageDay <<endl;
    else
    outFile << AverageEvening <<endl;
    }

  15. #30
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    if you want us to try something, please include all your code... but from what I saw:
    Code:
    while (!inFileDay.eof() )
    {
        int score1, score2, score3, score4, score5;
        int studentcounter;
        double AverageDay, AverageEvening, largest = 0;
    
        inFileDay>>score1>>score2>>score3>>score4>>score5;
        AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
        studentcounter++;   //did you initialize
        {
            while (studentcounter<=23)  //rethink this loop
            {
                ++studentcounter;   //did you want to reinitialize this?
                if (AverageDay > largest)
                    AverageDay = largest;
            }
            outFile<<AverageDay<<endl;
        }
    }
    
    while (!inFileEvening.eof() )
    {
         inFileEvening>>score1>>score2>>score3>>score4>>score5;
         AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
         studentcounter++;  //where was studentcounter initialized?
         {  //why this bracket?
            while (studentcounter<=23)  //rethink this loop
            {
                ++studentcounter;   //did you want to reinitialize this
                if (AverageEvening > largest)
                    AverageEvening = largest;
            }
            outFile<<AverageEvening<<endl;
        }
    }
    
    if (AverageDay > AverageEvening)
    {
        outFile << AverageDay <<endl;
    }       //don't forget your brackets
    else
    {       //again, watch that
        outFile << AverageEvening <<endl;
    }
    try formatting your code a little better, too... the colors are extra, but at least try keeping the spacing up...

    also, I can tell it's not going to work, because all you read in are the scores... you're forgetting about the names and student ID.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 05:24 PM
  2. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 09:52 AM
  3. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  4. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 08:31 PM
  5. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21