0
My Output is incorrect
My friend helped me with this program, it is used to find the number of lines in a file, average characters per line, the line with the most amount of characters and the line with the least amount of characters (Longest and Shortest Line) the output for the shortest line is incorrect and Im not sure how to fix https://code.sololearn.com/cf4aw5EI41Db
2 ответов
+ 3
Instead of this;
if( Count > Longest_Line ) {
Longest_Line=Count;
Longest_Line_No=Line_Number;
} else if ( Count < Shortest_Line) {
Shortest_Line=Count;
Shortest_Line_No=Line_Number;
}
Try setting Longest_Line to the max of Longest_Line or Count, and set the Shortest_Line to the min of Shorest_Line and Count for each iteration of the loop.
The above code only sets one or the other making it possible to skip when one should have been set. For instance the first line will be set to the longest which is true (at that time), but it is also the shortest. If that line is in fact the shortest of all lines then it will be incorrect and actually be set to a longer line.
0
I had my friend help me with it