-4

https://onlinegdb.com/r1jGMHRPO This is my final project for the class and since it's online, i dont really have many resources that i can get help from so i thought i might post this here. I used a while loop to create an array from the data from a text file "numbers.txt" and made function for lowest, highest, total and average that were later called to display the results but for some reason i keep getting the first number of the array as the answer for all of them. Any help will be appreciated.

  • 3
    Welcome to Stack Overflow. Please take the time to go through the [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) on what and how you can ask here.It's specially important to post a [mcve]. Posting a link to code is not acceptable here. – R Sahu May 04 '21 at 03:48

2 Answers2

1

You are returning the highest, lowest, etc. as soon as you find the first value that is lower than your predefined min and max values. Move the return; keyword outside of the for loop. Also, you should use int lowest = INT_MAX and int highest = INT_MIN because there could be a number higher than 100k and so on. Also, move the return sum; outside the scope of the totalSum forloop too.

-1

your code work just fine on my environment.
maybe your problem is your numbers.txt file is not at the exe file's location, so the file is not found and eof never reached.
put your numbers.txt file at the exe file's location or you have to check it first when you want to read from it. You can check the way to do it here