Write a program to compute the current in an AC circuit that has three resistors R1, R2, and R3, in parallel. The voltage source is V. Test your solution with various voltage levels and resistor values. Execute and submit the program and the results in screen captures. Repeat the problem if the resistors are in series.
I started with the Series code first since its the easiest but I'm not getting the correct current output. It keeps saying the current is 0, regardless of what numbers I put in rather than doing the actual calculations.
#include <stdio.h>
int main(void)
{
int R1; //First Resistor
int R2; //Second Resistor
int R3; //Third Resistor
int V ; // Voltage Source
printf(" Enter first resistor: \n"); //prompt for R1
scanf( "%d", &R1);
printf(" Enter second resistor: \n");//prompt for R2
scanf( "%d", &R2);
printf(" Enter third resistor: \n");//prompt for R3
scanf( "%d", &R3);
printf(" Enter the voltage source: \n");//prompt for V
scanf( "%d", &V);
int current;
current = current = V/ (R1 + R2 + R3) ; ;
printf("The current is: %d\n", current);
return 0;
}
Integer division will truncate the fractional part, so if your expect current was 0.5A, the calculated current would be 0A, as integers can only store whole numbers.
To fix this, simply use doubles.