473,414 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Finding Max and Min using cin

24
Write a program that reads daily temperatures, as floats. Read in a loop until an EOF. After the input has been read, print the maximum and minimum values. You can assume that there is at least one input data value.
Sample input values

10.0 11.3 4.5 -2.0 3.6 -3.3 0.0


The output should look something like the following. Formatting may vary.

Maximum = 11.3
Minimum = -3.3

Hi... Can anyone show me how to write this program?
Sep 4 '06 #1
4 25162
Banfa
9,065 Expert Mod 8TB
You can read the file using the functions

fopen
fgets
fclose

I suggest you don't use fscanf

then you can use

strtof

to convert the text into binary values, store these values in an array or list.

As you read the values check them to see if you have a maximum or minimum and store the maximum and minimum for later use.


Expand|Select|Wrap|Line Numbers
  1. OPEN FILE
  2.  
  3. do
  4. {
  5.    IF FIRST TIME OR INPUT BUFFER EMPTY
  6.       READ FILE INTO INPUT BUFFER
  7.    ENDIF
  8.  
  9.    GET BINARY VALUE FROM INPUT BUFFER
  10.  
  11.    IF GOT BINARY VALUE
  12.       IF FIRST VALUE
  13.          MIN = MAX = VALUE
  14.       ELSE
  15.          IF VALUE > MAX
  16.             MAX = VALUE
  17.          ENDIF
  18.  
  19.          IF VALUE < MIN
  20.             MIN = VALUE
  21.          ENDIF
  22.       ENDIF
  23.  
  24.       STORE VALUE
  25. } while(INPUT BUFFER NOT EMPTY AND NOT EOF)
  26.  
  27. CLOSE FILE
  28.  

[/code]
Sep 4 '06 #2
Nhd
24
Hi, this program is not really working... when i run it, there's an error which states "cin", "cout" and "endl" are undeclared (first use this function).. But why should i declare cin, cout and endl? There's supposed to be no need for any declaration for these rite...?

#include<iostream>

void min_max (int one, int two, int three, int& min, int& max);

main()
{
int a,b,c,min,max;
cin>>a>>b>>c;
min_max(a,b,c,min,max);
cout<<"Minimum "<<min<<endl;
cout<<"Maximum "<<max<<endl;
}


void min_max (int one, int two, int three, int& min, int& max)
{
min = one;
max = one;
if (two > max) max = two;
if (two < min) min = two;
if (three > max) max = three;
if (three < min) min = three;
}
Sep 4 '06 #3
D_C
293 100+
Add #include<stdlib.h> and the code will run.
Sep 4 '06 #4
Nhd
24
Hi.. i tried but the error is still there.... But i think im on the wrong track after thinking back...

My input sample is like this:

File 1 File 2 Lines Matched
File1-0(71%) File2-0(63%) 177
File1-1(59%) File2-1(63%) 167
File1-2(49%) File2-2(54%) 101
File1-3(42%) File2-3(51%) 130
File1-4(53%) File2-4(47%) 92
File1-5(58%) File2-5(57%) 109
File1-6(43%) File2-6(48%) 183
File1-7(48%) File2-7(50%) 80
File1-8(38%) File2-8(45%) 81
File1-9(40%) File2-9(41%) 71
File1-10(38%) File2-10(32%) 64
File1-11(17%) File2-11(29%) 61
File1-12(28%) File2-12(26%) 65
File1-13(22%) File2-13(18%) 50
File1-14(13%) File2-14(11%) 20
File1-15(16%) File2-15(14%) 28
File1-16(17%) File2-16(16%) 34
File1-17(14%) File2-17(13%) 23
File1-18(14%) File2-18(10%) 41

Im trying to get the max, min, average and standard deviation for the percentage of file 1 which are in this case those in the brackets (..%).

So im able to get an output like this:

number of records: 19
maxp1 = 71 minp1 = 13 avgp1 = 35 stdevp1 = 19

That is why in my another post, im trying my best to count the number of lines being read.... can anyone help me... i really need help... thks so much....
Sep 4 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Helge Jensen | last post by:
Having posted in microsoft.public.dotnet.framework.sdk and microsoft.public.dotnet.framework.wmi without receiving any response, I posthere on the off-chance that someone who isn't following those...
3
by: KL | last post by:
Well, I am back. This time our assignment has us filling a vector and then timing how long it takes to find a spot in the vector to insert a new item, and the time required to insert the item...
1
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during...
8
by: Tor Inge Rislaa | last post by:
Finding the width of a text I need to find the width of a text. When the user change the font in a textbox I want the textbox to fit the text automatically by changing txtMyTextBox.Width...
9
by: dave m | last post by:
I need to be able to retrieve a unique ID from a users PC. I needs to be something a user could not easily change, like the computer name. Could someone point me in the right direction to find ...
15
by: cwsullivan | last post by:
Hi gang, I have a grid full of particles in my program, and I want to find an angle between two particles. I'm having trouble because it seems like the answer depends on whether or not the target...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
0
by: NSF12345 | last post by:
Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\oldpc\main share\Folder\file.txt") Then" way of...
1
by: me | last post by:
Hi, Im having a few issues with finding exactly which program may be accessing a certain file. Lets say I need to replace a DLL with a newer version, but I need to make sure its not being...
4
by: karthik25 | last post by:
Hi All, I have a problem in finding control in a dynamically created updated panel. I have given the code below. Following is just a starting effort in a completely dynamic user control. I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.