Thread: Equivalent Resistance of ciircuit

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    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;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You keep using the variables R_series and R_par but I don't see them declared anywhere.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by tabstop View Post
    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.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    6
    the r array is scanned in the two call functions and has a max memory of 100 elements

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by jjzarabi View Post
    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.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string equivalent of sprintf()
    By e66n06 in forum C++ Programming
    Replies: 4
    Last Post: 08-16-2007, 03:30 PM
  2. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 08:22 PM
  3. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  5. Replies: 0
    Last Post: 11-01-2002, 11:56 AM

Tags for this Thread