473,382 Members | 1,368 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,382 software developers and data experts.

read in a numbers of line in a file and compute the min, max & mean of each line

Hi,

I am writing a program that read a file that contains lines of integers

the program needs to print out the mean of the integers, the integer with the minimum value, and the integer with the maximum value for each line.

the attached is what i have done. but the output is different from the expect output.

Because i am beginner of C++, can any one explain to me what i have done wrong?

Thanks a lot!
Attached Files
File Type: txt stat.txt (1.3 KB, 397 views)
Nov 16 '11 #1
1 2140
Banfa
9,065 Expert Mod 8TB
You calculate your mean as you go along but the mean needs to be calculated at the end once you know the total value of all numbers and the count of numbers.

By contrast you calculate min and max at the end, testing the same value of x repeatedly but you need to calculate min and max as you go along testing each value of x input. Also For the min calculation you initialise min to 0 then test if min > x. IF min is already 0 when is it likely to be greater than x?

And finally you don't use code indentation consistently making it harder for you to spot these problems.
Nov 17 '11 #2

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

Similar topics

6
by: sea | last post by:
I have text files in the following format: 123,34, ,345,890, 123,23 .. .. .. As you can see, the problem is that (1) the commas can occur in
5
by: Knackeback | last post by:
task: - read/parse CSV file code snippet: string key,line; typedef tokenizer<char_separator<char> > tokenizer; tokenizer tok(string(""), sep); while ( getline(f, line) ){ ++lineNo;...
1
by: Gunnar G | last post by:
I have a file with numbers (all integers) 123,14,5,2,141345,3,4545, and so on where there is a , (comma) between every integer or the comma can be replaced with a newline. How do I put all these...
8
by: microsoft.news.com | last post by:
I have a text file that has a column of numbers that i need to add to get a total of. Is there any way to add the number column in my text file? the text file looks like this: BMW ...
5
by: dean | last post by:
sSQL = " update SELECTED_NODES " " set LABEL_S = 'Y' " " where NODE_I in " " ( " " select NODE_I " " from " " ( " " select ONODE_I NODE_I from link " " union all "
2
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
12
by: Matt F | last post by:
I'm creating simple ping script that prompts a user for various parameters. However, I would like each line of the ping displayed as it is received. Currently, the result isn't displayed until...
5
by: unknown418 | last post by:
I am confused what is the efficient way to read in a file with multiple values per line. Each value is separated by a space character. The values could be characters or real values. I am using...
10
by: vincex200 | last post by:
My group needs help with this program. We attempted to start it and got no where. Please help us. Write a C++ program that will read data from a file, perform computation on the data, then print...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.