calculating average

This is a discussion on calculating average within the C++ Programming forums, part of the General Programming Boards category; #include "stdafx.h" #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int NumStudents=1; int main() { char name [20][10]; ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    calculating average

    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    using namespace std;

    const int NumStudents=1;

    int main()
    {
    char name [20][10];
    int grades [20][8];
    int i, j, n;
    float sum, average;
    ifstream classFiles;
    classFiles.open ("c:\\231.txt");
    if (!classFiles)
    {
    cout<<"You Screwed Up \n\n";
    return 0;
    }
    for (i=0; i<NumStudents; i++)
    {
    classFiles>>name[i];
    for (j=0; j<8; j++)
    classFiles>>grades[i][j];
    }

    for (i=0; i<NumStudents; i++)
    {
    sum=0;
    sum = sum + grades [i][j];
    average = sum/8.0;

    cout<<setw(10)<<name[i]<<" ";

    for(j=0; j<8; j++)
    cout<<setw(4)<<grades[i][j]<<" ";
    cout<<" "<<average<<endl;

    }


    return 0;

    }
    Code:
    CODE

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Welcome to the board
    Please help yourself to our FAQ.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    AVERAGE

    YOU NEED TO FLOAT: CLASSAVERAGE & TOTAL

    classaverage=total/(numstudents*8);

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. calculating average
    By coolca in forum C Programming
    Replies: 1
    Last Post: 10-11-2006, 05:55 PM
  4. Calculating an average
    By Andy123 in forum C Programming
    Replies: 11
    Last Post: 03-02-2006, 09:40 AM
  5. Problem calculating average with "for"...
    By davidvoyage200 in forum C++ Programming
    Replies: 3
    Last Post: 10-25-2002, 10:02 AM

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