formatting problem

Hi, I was wondering how I can get the terms "honors, warning" on the same line as the GPA/ID number when one gets honors or warning. Thanks

Sry for all the commented out lines.


output looks like this:

http://i13.photobucket.com/albums/a276/vcsniper/5v2_zps6808e96b.jpg


Would like to make it look like this: notice Honors and Warning on same line.
Student GPA Special Note
1001 2.625
1002 3.800 Honors
1003 1.050 Warning
1004 3.500 Honor


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cstring>


using namespace std;

int main()
{
cout <<"A\n";
double gpa, grade1, grade2, grade3, grade4;// grades for student each student
double courseTotal1, courseTotal2, courseTotal3, courseTotal4;
double courseAvg1, courseAvg2, courseAvg3, courseAvg4; // total course grade divided by number of students
int idnumber, numStudent; //id number
// number of student
ifstream inputFile;
string filename;


cout << setprecision (2) << fixed;



/*int i=0;
for(int counter = 0; i < 3; ++i)
{
std::string filename;
std::cout << "Enter name of the file to open: ";
std::cin >> filename;
string path;
path= "C:\\Users\\\Documents\\";
filename = path + filename;
cout << filename <<endl;


}

inputFile.open(filename.c_str());
inputFile.open("C:\\Users\\\\Documents\\run1.txt", ios::in);
if(!inputFile)
{
cout <<"**EMPTY FILE…NO DATA TO PROCESS**" <<endl;
system("Pause");
exit(1);
}*/


inputFile.open("C:\\Users\\\\Documents\\run1.txt");
if(!inputFile)
{
cout <<"**EMPTY FILE…NO DATA TO PROCESS**" <<endl;
system("pause");
exit(1);
}
ofstream outputFile;

//outputFile.open("C:\\Users\\\\Documents\\Outputfile1.txt",ios::out);

/*if ( outputFile.fail() )
{
cerr << "\a\aOutput file could not be opened" << endl;
exit(1);

}*/



numStudent = 0;
courseTotal1 = 0;
courseTotal2 = 0;
courseTotal3 = 0;
courseTotal4 = 0;

cout <<"\t\tStudent"<<setw(15)<<"GPA"<<setw(25)<<"Special Note\n"<<endl;
while(inputFile >> idnumber >>grade1 >>grade2 >>grade3 >>grade4)
{
gpa = (grade1 + grade2 + grade3 + grade4)/4;
/*if (numStudent=0)
cout <<"\t\tStudent"<<setw(15)<<"GPA"<<setw(25)<<"Special Note\n"<<endl;*/
cout << setw(20)<< idnumber << setw(20) << gpa <<endl;
// setw(5)<<grade2<< setw(5)<<grade3 << setw(5)<<grade4;
//gpa = (grade1 + grade2 + grade3 + grade4)/4;

/*if (gpa =< 3.5 && >=1.5)
cout << "\t\t" << idnumber << setw (15) << gpa << endl;*/

if(gpa >= 3.5)
cout << setw(60)<< "Honors\n" ;

if(gpa <= 1.5)
cout << setw(60)<< "Warning\n" ;

//else
//cout << setw(70) ;

courseTotal1 += grade1;
courseTotal2 += grade2;
courseTotal3 += grade3;
courseTotal4 += grade4;
numStudent = +1;
}



if (numStudent= 0)

cout << setw(15) << "File Empty";

else
courseAvg1 = courseTotal1/numStudent;
courseAvg2 = courseTotal2/numStudent;
courseAvg3 = courseTotal3/numStudent;
courseAvg4 = courseTotal4/numStudent;

cout << "\n\n\t\t Course 1 average: "<<setprecision(4)<<showpoint<<courseAvg1<<endl;
cout << "\t\t Course 2 average: "<<setprecision(4)<<showpoint<<courseAvg2<<endl;
cout << "\t\t Course 3 average: "<<setprecision(4)<<showpoint<<courseAvg3<<endl;
cout << "\t\t Course 4 average: "<<setprecision(4)<<showpoint<<courseAvg4<<endl;




inputFile.close();


outputFile.close();

system("PAUSE");

return 0;

}
Last edited on
Topic archived. No new replies allowed.