Solved

C++ Builder

Posted on 2003-10-24
2
189 Views
Last Modified: 2010-04-17

I'm a novice.

I want to read two pairs of values from a simple file (that can be positive or negative) to determine which are the lowest and highest. The file is just that, a series of values, however teh first one is an x co-ordinate and the second a y co-ordiante.

I have some code that works for a single value, how do I mod it for two.

points=0;
  maxheight = 0;
  while (file1>>height){
   points++;
   if (height>maxheight)
     maxheight=height;
     }
  file1.close();
    }

This code extracts one value for height and determines the max value. teh file I am looking at detemines heading.

I know this is scandously overpriced in terms of points, but I need help and we're thick in th UK. And yes, it's a college assignment ........

Madoc




0
Comment
Question by:madoc
2 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9615419
Hi madoc,

so what does you file look like?

<x> <y>
 
or

<x>
<y>
<x>
<y>
<x>
<y>
...

Cheers!
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 250 total points
ID: 9615462
madoc,

> I have some code that works for a single value, how do I mod it for two.

  #include <limits.h>

  int width;

  points = 0;
  maxheight = INT_MIN;
  maxwidth = INT_MIN;
  minheight = INT_MAX;
  minwidth = INT_MAX;
  while ( (file1>>height) && (file1>>width) )
  {
    points++;
    if ( height > maxheight )
       maxheight = height;

    if ( height < minheight )
       minheight = height;

    if ( width > maxwidth )
       maxwidth = width;

    if ( width < minwidth )
       minwidth = width;
  }
 
  file1.close();


Hope that helps,
Dex*
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question