Help with code

Hey guys I'm having some trouble with this code, I am suppose to find voltage by multiplying a resistance array and a current array by using a function and pointers. This is what I have so far:

#include "stdafx.h"

#include <iostream>

using namespace std;

#include <iomanip>

#include <fstream> // Hey, we haven't seen this yet!!!!

#include <string>

#include <new>



void determineVoltage(double *,double *, double *);


int main()

{

double current [10] = {10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98};

double resistance [10] = {4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, 4.8};

double voltz [10]= {0};

double *c;

double *r;

double *v;



c = current;

r = resistance;

v = voltz;



determineVoltage(c, r, v);



for(int i=0; i < 10; i++)

{

cout << "*(voltz + " << i << ") : ";

cout << *(v + i) << endl;

}





return 0;

}



void determineVoltage(double *cur,double *ress,double *volt, double numels)

{

for(int i=0; i < numels; i++)

{
(volt+i)=(cur+i)*(ress+i);
}

}
Last edited on
change determineVoltage() prototype to accept three double pointers and one double.

call determineVoltage(c, r, v, 10) in main()

change this line in determineVoltage():
(volt+i)=(cur+i)*(ress+i);
to this:
*(volt+i)=(*cur+i)*(*ress+i);
Topic archived. No new replies allowed.