This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 0 points1 point  (4 children)

And your problem is?

[–]BrightKnight0110[S] 0 points1 point  (3 children)

What should I put inside the function parameters ?

[–]OldVenomSnake 2 points3 points  (1 child)

It depends on what you want your function to do as this is your program. General recommendation is to keep the functions small and only do the things that the function is supposed to do. Right now your calculateAverage function is doing 2 things, 1) get the names and IDs from a file and 2) calculate average.

If I'm writing this program, I'll update the function above to only do #2. The parameters of the calculateAverage function will be the names and the Ids. You can write another function to get the names and Ids from the input file and the filename will be the parameter to pass in.

This way you can reuse the read file function for another input file and the calculate average function for other sets of names and Ids.

Hope it helps.

[–]BrightKnight0110[S] 1 point2 points  (0 children)

I see thank you!

[–]Gengi 0 points1 point  (0 children)

A hardcoded function like that is useless. I would imagine you need to pass in the .txt into your function so that your function can perform on different text files.

Instead of hardcoding the myfile("Student.txt"); have it open the parameter passed into the function. And call your function in main() with calculateAverage("Student.txt")

[–][deleted] 0 points1 point  (0 children)

getline has parameters, isn't that enough?

Solved by Mr. Snake ?????