### Program only returning 1st value of array

I'm writing code that declares 3 arrays in main then sets the 3rd equal to the 1st multiplied by the 2nd in another function. It's then supposed to give display
the 3rd array within the main function. For some reason, when I run it it repeats the 1st value over and over instead of listing the following ones.
 ``12345678910111213141516171819202122232425262728293031323334353637`` `````` #include #include #include using namespace std; int i; double calcVolts(const double *current, const double *resistance, double *voltage) { for(i=0; i<10; i++) { voltage[i] = current[i] * resistance[i]; return voltage[i]; }} int main() { const int num=10; double current[num] = {10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98}; double resistance[num] = {4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, 4.8}; double voltage[num]; for (int i=0; i

The output is Voltage number 1 is: 42.48
Voltage number 2 is: 42.48
Voltage number 3 is: 42.48
Voltage number 4 is: 42.48
Voltage number 5 is: 42.48
Voltage number 6 is: 42.48
Voltage number 7 is: 42.48
Voltage number 8 is: 42.48
Voltage number 9 is: 42.48
Voltage number 10 is: 42.48

What am I doing wrong?
Your calcVolts function doesn't need to return anything, make it void and remove return statement on line 17. Call it once before you start printing out your answers in main.

 ``123456`` ``````//In main() after arrays are declared calcVolts(current, resistance, voltage); for (int i=0; i
Topic archived. No new replies allowed.