|
-
February 11th, 2011, 01:17 PM
#1
Do functions compute before being called?
So I'm writing a simple program to calculate the standard deviation of a 1D array of integers. Main starts off with a function for the user to input the values of the array. Then the standard deviation function is called.
In the function for the standard deviation I include:
cout << "hello" << av << "hello" << endl;
to test if the average for the array values was correct.
Everything is normal, except for the fact that the line above is executed immediately after entry of the final array element, before I call the function, and before the first cout statement after array input. The relevant code was:
input_array(a,n);
cout << "The standard deviation of a's array elements is: \n\n";
cout << standard_deviation(a,n) << endl;
So the result in console was something like:
Input Array: 5 7 9
hello7hello
The standard deviation of a's array elements is: 1.63299
How come this happens?
KingG
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|