|
Questions about circuits?
Okay, hopefully someone can help sort out my confusion and frustration with some electromagnetic stuff. Please answer any part of any question if you can.
(1) when considering a circuit with two batteries and two resistors, why is it that we have the batteries' positive terminals "face" each other? In my book it goes like this:
(-l|l|+)=>=(resistor)=>=(+|l|l-)=>=(resistor)=>
(only of course the two ends are connected, since this is a circuit).
Doesn't the current flow from negative to positive terminal? and wouldn't it make more sense to connect the circuit this way:
(-l|l|+)=>=(resistor)=>=(-l|l|+)=>=(resistor)=>
i.e., positive and negative facing?
(2) Here is a question from my book that I don't know how to answer: "A circuit consists of two batteries, a resistor and a a capacitor, all in a series. Does the description allow any flexibility?" I have read the text very carefully while taking notes, and there is literally nothing that prepares to answer this question AT ALL, which is extremely frustrating because I am trying to understand. I can calculate various quantities like the current, voltage and resistance across and through various components in various circuits, but I don't understand why they are connected as they are, and why they can or cannot be connected in other ways. For example, does a resistor always separate a battery from a capacitor? Why or why not?
(3) This brings me to an even more fundamental question, which is why we need resistors at all? Don't they lower the power we can get from a given source? In my book it is never stated that a circuit with emf couldn't exist without a resistor, yet they never show one. Is this to do with the phrase "short circuit," which my book defines as "a circuit with 0 resistance." What is so bad about that?
Get the answers...
|
|
Help with debugging C program?
Hey, basically I need help trying to debug and make this program work. It's a program to use ohm's law to find either voltage, current, or resistance. I can't seem to understand or find a way to get the desired output here. I think the problem is in the assign_vals function, but i'm not 100%. Any input would be appreciated. The input is as follows when trying to find voltage:
voltage
resistance 100 current 2
// resulting output
voltage = 200
resistance = 100
current = 2
#include
#include
#include
void process_voltage (double resistance, double current);
void process_resistance (double current, double voltage);
void process_current (double voltage, double resistance);
void assign_vals (char var1[], double val1, char var2[], double val2);
void display_result (char var1[], double val_1,
char var2[], double val_2, char var3[], double val_3);
int main ()
{
double voltage;
double resistance;
double current;
char operation[12];
int op_check;
operation[11] = '\0';
op_check = scanf("%s", operation);
while (op_check == 1)
{
if (strcmp(operation, "voltage") == 0)
{
process_voltage(resistance, current);
op_check = scanf("%s", operation);
}
if (strcmp(operation, "resistance") == 0)
{
process_resistance(voltage, current);
op_check = scanf("%s", operation);
}
if (strcmp(operation, "current") == 0)
{
process_current(voltage, resistance);
op_check = scanf("%s", operation);
}
else
{
printf("bad option %s. exiting\n", operation);
exit(1);
}
}
printf("\n");
return 0;
}
void process_voltage (double resistance, double current)
{
double voltage;
assign_vals("resistance", resistance, "current", current);
voltage = resistance * current;
display_result("resistance", resistance, "current", current, "voltage", voltage);
}
void process_resistance (double current, double voltage)
{
double resistance;
assign_vals("voltage", voltage, "current", current);
resistance = voltage / current;
display_result("voltage", voltage, "current", current, "resistance", resistance);
}
void process_current (double voltage, double resistance)
{
double current;
assign_vals("voltage", voltage, "resistance", resistance);
current = voltage / resistance;
display_result("voltage", voltage, "resistance", resistance, "current", current);
}
void assign_vals(char var1[], double val_1, char var2[], double val_2)
{
double value1;
double value2;
char str1[12];
char str2[12];
str1[11] = '\0';
str2[11] = '\0';
scanf("%s %lf %s %lf", str1, &value1, str2, &value2);
if (strcmp(str1, str2) == 0)
{
printf("not enough unique variables. exiting\n");
exit(1);
}
else if (strcmp(str1, var1) == 0 && strcmp(str2, var2) == 0)
{
val_1 = value1;
val_2 = value2;
}
else if (strcmp(str1, var2) == 0 && strcmp(str2, var1) == 0)
{
val_1 = value2;
val_2 = value1;
}
else
{
printf("variables are not valid for this option. ");
printf(" exiting\n");
exit(1);
}
}
void display_result(char var1[], double val_1,
char var2[], double val_2, char var3[], double val_3)
{
printf("\n\n");
printf("%s = %0.2lf\n", var1, val_1);
printf("%s = %0.2lf\n", var2, val_2);
printf("%s = %0.2lf\n\n", var3, val_3);
}
Get the answers...
|