# Equivalent Resistance of ciircuit

• 12-07-2010
jjzarabi
Equivalent Resistance of ciircuit
What is wrong with this code?

Code:

```#include <stdio.h> int R_series(int r[100]); int R_par(int r[100]); int main (){ //Jeremy Zarabi //ESE 124 HW 12 int num1, start=1; while (start==1){ printf("Enter 0 to quite\n Enter 1 for series circuit\n Enter 2 for parallel circuit: "); scanf("%d",&start); if (start==0){         return 0; } else if (start==1){ R_series=R_series(r); printf("Equivalent Resistance of your circuit=%d Ohms\n",R_series); printf("Enter 0 to quite\n Enter 1 for series circuit\n Enter 2 for parallel circuit: "); scanf("%d",&start); } else if (start==2){ R_par=R_par(r); printf("Equivalent Resistance of your circuit=%d Ohms\n",R_par); printf("Enter 0 to quite\n Enter 1 for series circuit\n Enter 2 for parallel circuit: "); scanf("%d",&start); } else if (start==0||start==1||start==2)         printf("Error!") } } int R_series (int r[100]){ int num1; printf("How many resistors are connected in series: "); scanf("%d",&num1); printf("Enter value of each resistance: \n"); for (int i=0;i<num1;i++) {         printf("\nR_%d: ", i+1);         scanf("%d",&r[i]); } for (int j=0;j<num1;j++)         R_series+=r[j]; } int R_par(int r[100]){ int num2; printf("How many resistors are connected in parallel: "); scanf("%d",&num2); printf("Enter value of each resistance: \n"); for (int i=0;i<num1;i++) {         printf("\nR_%d: ", i+1);         scanf("%d",&r[i]); } for (int k=0; k<num2;k++){         R_par+=(1.0/r[i]); } R_par=1.0/R_par; }```
• 12-07-2010
tabstop
You keep using the variables R_series and R_par but I don't see them declared anywhere.
• 12-07-2010
stahta01
Quote:

Originally Posted by tabstop
You keep using the variables R_series and R_par but I don't see them declared anywhere.

I think they are functions; but, where is the "r" array of 100 ints defined?

Tim S.
• 12-07-2010
jjzarabi
the r array is scanned in the two call functions and has a max memory of 100 elements
• 12-07-2010
tabstop
Quote:

Originally Posted by jjzarabi
the r array is scanned in the two call functions and has a max memory of 100 elements

Yes, but you have to pass a real, actually-existing array into the function. Which you don't. You also can't try to use the name of a function inside the function as a variable, because after all this isn't Fortran. (All your variables need to be declared, when it comes down to it. Start declaring some variables.)