c++ help
Problem: You are to create a program that uses a loop to input floating-point numbers from a file, count how many numbers that were in the file, determine the minimum value in the file, determine the maximum value in the file. Use the state of the extraction operator to control the loop. Do not use any Boolean variables in your code. Your output should be to the screen and be similar to the following
“There were ___________ numbers in the file. The maximum value was _____ and the minimum value was _____.”
These are all the numbers from the text file:
44.1690
49.6946
76.0417
96.9646
-8.6211
35.6206
170.2537
-22.6949
202.2135
152.5827
92.1522
114.6313
29.3209
84.7122
210.7721
106.7014
100.2840
27.8986
92.2244
126.0150
139.7839
68.8788
61.8592
216.9955
-20.5653
191.2920
198.3217
169.0460
-5.3219
35.4678
53.8392
139.9320
4.1383
150.3069
-3.3095
133.4393
93.5435
164.7629
148.7593
195.9301
192.7306
53.5408
144.6865
19.4525
-22.3648
156.0186
95.0056
89.9805
196.1806
122.4667
124.4166
184.8606
171.3724
114.1804
15.7306
29.9830
191.6280
-22.8315
92.4753
11.9818
214.6702
148.1736
95.1179
87.7721
-15.0953
140.4930
-19.3922
-12.1386
100.4125
-5.8175
174.5371
174.3868
150.6099
7.4664
134.9013
99.6487
213.2436
132.2479
170.0826
83.4494
78.0979
176.3284
-9.1325
3.2928
13.3472
67.7345
177.8449
170.8411
-14.8822
69.8144
101.7190
74.1999
134.2150
126.9933
42.9960
77.9128
-26.1282
216.0159
11.7921
-3.4459
63.1024
19.5296
92.4219
54.8734
207.9076
200.0830
-16.8308
154.4645
37.2799
75.7089
106.9677
205.6842
74.4360
215.7631
45.3637
145.2747
136.5847
104.7816
144.5264
136.6320
14.5331
2.0036
219.7701
12.7803
-21.8498
110.2999
190.4666
137.2938
17.6083
62.2291
85.1815
215.4095
9.1012
183.8807
131.1911
64.0681
17.7309
77.0632
90.5055
0.1529
117.3769
26.5469
66.1548
115.7466
32.9515
42.6102
124.2727
36.3202
176.0941
215.6658
152.5622
55.9693
116.0173
-3.0577
196.5770
189.9134
174.4401
35.1820
118.5891
-24.3719
76.3148
48.1797
10.3712
14.6915
75.7214
-6.4427
119.6309
87.7311
143.9873
144.9720
129.6327
-21.5990
-12.7985
49.8999
102.7161
133.6114
71.9048
174.9953
149.5897
212.1623
102.8335
51.2864
-3.5927
122.7397
164.7006
75.8632
-7.2942
36.6179
8.4142
40.2513
80.0213
101.7857
84.3561
188.8429
99.5130
205.9057
129.4273
209.4235
30.1768
139.0306
42.2661
137.9520
143.7851
-13.0018
33.6975
26.0100
136.9582
181.0980
56.1156
165.1299
138.8330
-28.3212
120.5426
66.6928
198.9978
-29.7122
85.6123
76.0873
85.2291
162.5399
50.6180
166.1848
87.8393
-21.0593
13.9686
150.4395
88.3715
8.1803
55.2812
121.8473
17.9363
154.6067
30.7124
199.3561
37.2654
161.3750
CODE:
#include<iostream>
//fstream library for operating with files
#include<fstream>
using namespace std;
int main()
{
//define a variable for storing minimum, maximum
and a temporary variable
float min, max, temp;
//a variable to count the number of floats
int numberOfFloats = 0;
//we define a fstream variable
fstream file;
//we open the file "data.txt" in input mode with
"ios::in"
file.open("data.txt", ios::in);
//if file is not opened, then we print an error
message and return 0, will exit the program
if(!file)
{
cout<<"File not
found";
return 0;
}
//we take the first value from file as input in
"temp"
file>>temp;
//we assign that temp value to min and max
variable
min = temp;
max = temp;
//we increment the count value to 1
numberOfFloats++;
//now we use a while loop with condition that
while file keeps on giving input in temp variable
while(file>>temp)
{
//we compare, if min is
greater than the current temp value, then we assign the "temp"
value to min
if(min>temp)
min = temp;
//we compare, if max is
less than the current temp value, then we assign the "temp" value
to max
if(max < temp)
max = temp;
//we increment the count
of number of floats
numberOfFloats++;
}
//output in the format specified
cout<<"There were "<< numberOfFloats
<< " numbers in the file. "
<<"The maximum
value was "<< max << " and the minimum value was "
<< min <<".";
}


INPUT:
In file "data.txt": data which you have given above








OUTPUT:
There were 236 numbers in the file. The maximum value was 219.77 and the minimum value was -29.7122.

Ask any questions if you have in comment section below.
Please rate the answer.
c++ help Problem: You are to create a program that uses a loop to input floating-point...