Maximum value from a test score

From an input file that contains scores, how to obtain the maximum val

Page 1 of 1

1 Replies - 623 Views - Last Post: 24 July 2008 - 12:37 AM Rate Topic: -----

#1 ozz_blade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 08

Maximum value from a test score

Posted 24 July 2008 - 12:02 AM

Attached is the file ("clac.dat") that contains all the scores, and I have to create a program that reads the files and output the highest value from the data into the screen. This is what I have done so far, and it is not giving neither errors nor warnings. However, it is displaying the wrong highest value (it displays zero as the highest value of the data) , and it should be 98 based on the input data (clac.dat).

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{   
	ifstream datafile;
	datafile.open("clac.dat");
	
while (datafile)
{
	int value[23];
	int highest = 0;

		for (int n = 0; n < 23; n++)
		{
			if (value[n] > highest)
			{
				highest = value[n];
			}
		}

	cout << "The highest value is " << highest << endl;
}
	datafile.close();
	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Maximum value from a test score

#2 joske  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 297
  • Joined: 04-September 07

Re: Maximum value from a test score

Posted 24 July 2008 - 12:37 AM

you forget to actually read the values from the file. You can do that with something like
datafile >> value[i];
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1