Solved

C++ Builder

Posted on 2003-10-24
2
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Make the most of your online learning experience.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

621 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