Nhd 24
New Member
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?
4 25186 Banfa 9,065
Recognized Expert Moderator Expert
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. -
OPEN FILE
-
-
do
-
{
-
IF FIRST TIME OR INPUT BUFFER EMPTY
-
READ FILE INTO INPUT BUFFER
-
ENDIF
-
-
GET BINARY VALUE FROM INPUT BUFFER
-
-
IF GOT BINARY VALUE
-
IF FIRST VALUE
-
MIN = MAX = VALUE
-
ELSE
-
IF VALUE > MAX
-
MAX = VALUE
-
ENDIF
-
-
IF VALUE < MIN
-
MIN = VALUE
-
ENDIF
-
ENDIF
-
-
STORE VALUE
-
} while(INPUT BUFFER NOT EMPTY AND NOT EOF)
-
-
CLOSE FILE
-
[/code]
Nhd 24
New Member
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<iostre am>
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,m in,max);
cout<<"Minimum "<<min<<end l;
cout<<"Maximum "<<max<<end l;
}
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;
}
D_C 293
Contributor
Add #include<stdlib .h> and the code will run.
Nhd 24
New Member
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....
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 groups
knows a solution.
I'm using code (roughly like):
using System;
using System.Management;
public class Foo {
|
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 after that spot is found.
Well, I am kinda lost on this finding things in a vector. I mean,
wouldn't you just go to vector, and then ....well then I gotta find
out how to do an insert in a vector. Does this involve changing the
pointer to point...
|
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
EventList_ItemCreated (below the html), but it's always <undefined
value> (null). Everything else works fine. Eventually I need to set
the value of the label depending up the Count of the DataView
"dvDiscount". For now I'll settle for just finding the damn...
|
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 according to the actual width of the text. It can also be
useful to know the actual height when using multiline textbox. Is this
possible?
TIRislaa
|
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 the information found in
Windows system information? Or maybe there is a better method.
Thanks in advance for any help or suggestions.
Dave M.
| |
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 particle is above or
below, in front or behind the refernce particle.
If I have a reference particle at (10,10), and another particle at
(20,20), i'm currently finding the angle by:
angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this...
|
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.
The SELECT query is built as follows:
$itemtype = stripslashes(trim($_POST));
|
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 finding if the file exists, but i want to make it so that it tries to look for the computer, not the file. At the moment this is how i am finding and copying the file:
If FileExists("\\oldpc\main share\Folder\file.txt") Then
FileCopy "\\oldpc\main...
|
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 accessed.
Finding out if its in use isnt a problem, but I need to find out
exactly which process is using it so I can ask the user if they would
like to end that process to replace the file or not.
|
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 experimenting before getting to the actual part. This is what I am trying to do:
* Create a tab container dynamically
* Create 5 tabs dynamically
* Add an update panel to each of the tabs
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |