Function for cout :(

Using a function to output values,

1
2
3
4
5
6
7
8
9
10
11
12
 double output(int& r1s, int& r2s, int& r3s, int& r4s, double gainmain, int r1, int r2, int r3, int r4, double* r)
{

	cout << "Actual gain   = " << gainmain << endl;
	cout << "R1 = " << r[r1] << " kohm" << endl;
	cout << "R2 = " << r[r2] << " kohm" << endl;
	cout << "R3 = " << r[r3] << " kohm" << endl;
	cout << "R4 = " << r[r4] << " kohm" << endl; 

 int main()
output(r1, r2, r3, r4, gainmain, r*);
}

the pointer uses an array but that shouldn't matter, the error im getting is
http://prntscr.com/4qpamt



i have all the needed library's just haven't included, im sure there is a simple way to fix this
Last edited on
That is because output function takes 10 parameters, but you passed 6 instead.

From your code, it is clearly shown that r is an array. Therefore, the output function could look like this instead:

1
2
3
4
5
6
double output( int r[], int const &size_of_r, int const & gainmain ){
    std::cout << "Actual gain = " << gainmain << std::endl;
    for ( int i = 0; i != size_of_r; ++i ){
        std::cout << "R" << i + 1 << " = " << r[i] << " kohm" << std::endl;
    }
}

I'm assuming R1 to R4 is contained in array r. Otherwise, r1s...r4s in the output parameters are redundant.

EDIT: If you really want to use that design and pass r1 to r4 explicitly to output, then you should 100% sure that they are valid subscript in r, otherwise you could be in a little trouble.You should be careful not to pass any value that are larger than the size of r
Last edited on
OxBADC0DE

You are right, I have saved values in r1s r2s r3s sr

I don't think i need to use an array again with the for statement,

I have changed the parameters to 6,


int main()

output(r1, r2, r3, r4, gainmain, r*);

i get an error with
http://prntscr.com/4qphcd
http://prntscr.com/4qpheb
Depending on what type r has you should either remove the * or place it before r.
Last edited on
Topic archived. No new replies allowed.