Solved

C++ Builder

Posted on 2003-10-24
2
190 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.

738 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