Passing the data from file to the function

Hello everyone ,

I need a small help for my c++ function. I am writing a function called "calculate". The Pr[o] array is a data in a file called "fileX" and is read from the file properly, there is no problem in that part. I have problem in the calculate function because Pr[o] is underlined with red , since it is error. I guess the filename should be the parameter of the calculate function. I do not know how to do that. How can I transfer these data which is read from the file in the function.Can you help me please ? Thank you so much

1
2
3
4
5
6
7
double calculate()
{			
for (int o = 0; o < 12; ++o) {
	yy += 5* Pr[o];
			}
return 0;
}
Last edited on
Hello.. learner999 ! You need to be more specific.. What you just shown is just a function that has only a loop inside.. You need to provide more code, we need to know what the function do calculate. Where did you open the fileX how did you do that.. ? With one single loop no one can help you.
Last edited on
Hello learner999,

How does this function know about the array "Pr"?

The same question would apply to "yy".

In both cases where are these variables defined? How does the function have access to them?

In the for loop using a lower case "o" is a bad idea. Usually "i", "j" and "k" are used in for loops and when working with an array I like to use either "index" or "idx" for better readability.

In 2 D arrays I like using "row" and "col".

Is there a point to having the function return a value the is just (0) zero?

Andy
Hello learner999,

In addition to what Mif said it is best to provide enough code to compile and test what you are having a problem with.

After thinking about the code I am thinking that you may need 1 or 2 parameters to the function and may want to "return yy" instead of (0).

Andy
Topic archived. No new replies allowed.