http://imageshack.us...s/253/picbl.jpg (sorry i can't post this picture here)
the number pairs are array elements, as you guys can see, i would like to add the word HW, LAB, Best etc..into the array so i can output something similar to the example above to a text file, i've already calculated all the required variables,
what i've tried is cout << setw(4) << 1 << set(w) << 2 etc...to manually draw out the layout that i want, it looks ok, but how do i output everything to a text file? there has to be a better way of doing this yeah?
#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "cmath"
#include "iomanip"
using namespace std;
int main()
{
double grade [2][5];
double averageLab = 0;
double averageHw = 0;
double totalLab = 0;
double totalHw = 0;
double bestLab = 0;
double worseLab = 0;
double bestHw = 0;
double worseHw = 0;
double averageClass = 0;
ofstream out;
out.open("temp.txt");
for(int i = 0; i < 5; i ++)
{
cout << "please enter your grade percentage for your"<< i + 1<<" lab assignment" << endl;
cin >> grade[0][i];
}
for(int j = 0; j < 5; j++)
{
cout << "please enter your grade percentage for your " << j + 1 << "hw assignment" << endl;
cin >> grade[1][j];
}
for( int k = 0; k < 5 ; k++)
{
totalLab += grade[0][k];
totalHw += grade[1][k];
averageLab = totalLab / 5;
averageHw = totalHw / 5;
bestLab = grade[0][k];
worseLab = grade[0][k];
if(grade[0][k] > bestLab)
{
bestLab = grade[0][k];
}
else if(grade[0][k] < worseLab )
{
worseLab = grade[0][k];
}
}
for(int y = 0; y < 5 ; y ++)
{
bestHw = grade[1][y];
worseHw = grade[1][y];
if(grade[1][y] > bestHw)
{
bestHw = grade[1][y];
}
else if(grade[1][y] < worseHw)
{
worseHw = grade[1][y];
}
}
averageClass = (averageHw + averageLab) / 2;
if(averageClass < 50.00)
{
cout <<" your average for the class is : " << averageClass << endl;
cout << " you didnt pass the class because your average is less than 50%" << endl;
}
else
{
cout <<"your average for the class is : " << averageClass << endl;
cout << "congratulation you passed the class" << endl;
}
cout <<"Best Lab = " << bestLab << endl;
cout <<"Worse Lab = " <<worseLab << endl;
cout <<"best Hw = "<< bestHw << endl;
cout <<"Worse Hw = " << worseHw <<endl;
system("PAUSE");
}

New Topic/Question
Reply




MultiQuote





|