programs runs but values are not correct, all it says is stack around the variable "exam" was corrup

Posted by user320950 on Stack Overflow See other posts from Stack Overflow or by user320950
Published on 2010-04-30T23:00:08Z Indexed on 2010/04/30 23:37 UTC
Read the original article Hit count: 258

Filed under:
|
|
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int read_file_in_array(double exam[100][3]);
double calculate_total(double exam1[], double exam2[], double exam3[]); // function that calcualates grades to see how many 90,80,70,60
//void display_totals();
double exam[100][3];
int main()
{
    double go,go2,go3;
    double exam[100][3],exam1[100],exam2[100],exam3[100];
    go=read_file_in_array(exam);
    go2=calculate_total(exam1,exam2,exam3);
    //go3=display_totals();
    cout << go,go2,go3;
    return 0;
}
/*
int display_totals()
{

    int grade_total;
    grade_total=calculate_total(exam1,exam2,exam3);
    return 0;
}   */
double calculate_total(double exam1[],double exam2[],double exam3[])
{
    int calc_tot,above90=0, above80=0, above70=0, above60=0,i,j, fail=0;
    double exam[100][3];
    calc_tot=read_file_in_array(exam);
    for(i=0;i<100;i++)
        {
        for (j=0; j<3; j++)
            {
            exam1[i]=exam[100][0];
            exam2[i]=exam[100][1];
            exam3[i]=exam[100][2];
            if(exam[i][j] <=90 && exam[i][j] >=100)
                {
                above90++;
                    {
                    if(exam[i][j] <=80 && exam[i][j] >=89)
                        {
                        above80++;
                            {
                            if(exam[i][j] <=70 && exam[i][j] >=79)
                                {
                                above70++;
                                    {
                                    if(exam[i][j] <=60 && exam[i][j] >=69)
                                        {
                                        above60++;
                                            {
                                            if(exam[i][j] >=59)
                                                {
                                                fail++;
                                            }
                                            }
                                    }
                                    }
                            }
                            }
                    }
                    }
            }
        }
    }
    return 0;
}

int read_file_in_array(double exam[100][3])
{
    ifstream infile;  
    int exam1[100];
    int exam2[100];
    int exam3[100];
  infile.open("grades.txt");// file containing numbers in 3 columns
    if(infile.fail()) // checks to see if file opended
        {
        cout << "error" << endl;
        }
    int num, i=0,j=0;
    while(!infile.eof()) // reads file to end of line
      {
          for(i=0;i<100;i++) // array numbers less than 100
          {
            for(j=0;j<3;j++) // while reading get 1st array or element
            infile >> exam[i][j];
            infile >> exam[i][j];
            infile >> exam[i][j];
            cout << exam[i][j] << endl;
                {
                    if (! (infile >> exam[i][j]) )
                    cout << exam[i][j] << endl;
                }
          exam[i][j]=exam1[i];
          exam[i][j]=exam2[i];
          exam[i][j]=exam3[i];
          }     
    infile.close();
  }
return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about arrays