I can not figure out how to go to the next line. In the data we read in number of test on the 1st line then student names followed by their test scores on the following lines. My problem is I can only get the first student and his average and that is it. Any help would be nice thanks.

#include <iostream>
#include <cmath>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	
	int tests;
int min;		
	int testScores;	
	int counter;	
	float sum;						
	float average; 
	string studentName;
	ifstream inData;
	
    inData.open("students.dat");
	
   if(!inData)  // file couldn't be opened
      cout << "Error: file could not be opened" << endl;

	
	min = 200;
	sum = 0;
	counter = 0;
	inData >> tests;
	inData >> studentName;

	while (inData)
	 	{ 
			
	cout << "Student's Name:" << studentName << endl;
			
	inData >> testScores;
			
		while (counter < tests)
		{
			
			if (min > testScores)
		
			min = testScores;
	
			
		sum = sum + testScores;
		
		inData >> testScores;
		
		counter++;
		 
		 }
		
		 
	sum = sum - min;
	
	average = sum / (tests-1);
	
	cout << "Test Average is:" << average << endl;
		
	inData >> studentName;	
	 
	 }

	return 0;
	
}

You have no condition for inData. Your telling it to just cheak inData you need a comparison. Eg != or == or > or <. Also I'm no sure use can use a ifstrem variable for that.
Woo 100th post man!

Edited 5 Years Ago by Zssffssz: n/a

You have no condition for inData. Your telling it to just cheak inData you need a comparison. Eg != or == or > or <. Also I'm no sure use can use a ifstrem variable for that.
Woo 100th post man!

I wrote the program like it says in my book ;\ , so im not to sure why it wont go to the next line in my data file( the next name and test scores). I dont know if it will help but heres the data im working with.
4
Adams 97 29 100 88
Brown 99 88 77 66
Carter 94 55 66 77
Davis 0 22 77 88
Wilson 77 55 88 55
I get Adams and his average but that is it ;\.

Edited 5 Years Ago by Stokes37: n/a

Books... Always outdated and full of problems. Did you chek to make sure your usin the same compiler as the book?

Comments
A completely worhless question.

Books... Always outdated and full of problems. Did you chek to make sure your usin the same compiler as the book?

We are using Linux Debian to compile and run them. Book doesn't say what it uses >.>.

Os doesn't usually matter unless using a system command... All I can think of is to rewite a do you want to exit at the end and attach the variable that the while uses to that. And Linux Usualy uses GCC or if you want to pay 500000$ a intel compiler.

Os doesn't usually matter unless using a system command... All I can think of is to rewite a do you want to exit at the end and attach the variable that the while uses to that. And Linux Usualy uses GCC or if you want to pay 500000$ a intel compiler.

yeah my bad its GCC and ok thanks.

This article has been dead for over six months. Start a new discussion instead.