Hey guys..
This assignment is due in class tomorrow, but im really stuck on it and cannot figure out why its not working. I have been trying for hours and no luck.
It will not find any errors or anything, but when I run it, it will not use the use input (E, R1, R2, R3) and send that out of the main program and get returned the values after the equations.
Basically, it gets up to the part where it will send the R1, R2, and R3 values out of the main and I get a program fault and it closes out.
I just don't know what I am not seeing here... So please, if any of you guys can help, please!
The assignment is under the code.
Here is the code I have so far!
-------------------------------------------------------------
Code:
#include <stdio.h>
#include <math.h>
int main ()
{
int E, R1, R2, R3, S, P;
void info (void);
int resist_P(int R1, int R2, int R3);
int resist_S(int R1, int R2, int R3);
printf("Please enter source voltage: ");
scanf("%i", &E);
printf("Please enter first of three resistors: ");
scanf("%i", &R1);
printf("Please enter second of three resistors: ");
scanf("%i", &R2);
printf("Please enter third of three resistors: ");
scanf("%i", &R3);
info ();
printf("E R1 R2 R3");
printf("\n%i\t%i\t%i\t%i\n\n", E, R1, R2, R3);
P= resist_P(R1, R2, R3);
S= resist_S(R1, R2, R3);
printf("Power for parallel Power for series");
printf("\n%6i %i", E*E/P, E*E/S);
printf("\n\nCurrent for parallel Current for series");
printf("\n%6i %i\n\n", E/P, E/S);
return 0;
}
void info (void)
{
printf("\n\nMy Student Information\n");
printf("ESC 151 Spring 08\n");
printf("Recitation 4, Feb 4, 2008\n\n\n");
return;
}
int resist_P(int R1, int R2, int R3)
{
int resist_p = 1/(1/R1+1/R2+1/R3);
return resist_p;
}
int resist_S(int R1, int R2, int R3)
{
int resist_s = (R1+R2+R3);
return resist_s;
}
---------------------------------------------------------------
And here is the assignment:
*The program asks for the user to input the source voltage, E, and resistance of three resistors, R1, R2, R3.
* Program has two functions resist_P(R1,R2,R3) and resist_S(R1,R2,R3) to calculate values of equivalent parallel and series resistances.
* It has a function power(voltage,R) to calculate the power consumed. The program prints the R1,R2,R3 and E values in the format below. The main calls power(voltage,R) twice, once to calculate and print the power for the parallel circuit and then for the series circuit. It also prints the current_parallel and current_sries. Output on the screen has the following format.
Hint: Parallel resistors= 1/ (1/R1+1/R2+1/R3)
Series resistors=R1+R2+R3.
Current= E/Equivalent resistance
Power= E*E/Reqv.