create a program that computes Voltage and Power of a circuit. I have everything up and running except for the looping part. I need to run the program for infinite times, until I enter 0, which will then calculate and sum everything up.
I need the result something like this:
printf ("+------------+------------+------------+------------+------------+\n");
printf ("| No of | Total | Average | Total | Average |\n");
printf ("| Circuits: | Voltage: | Voltage: | Power: | Power: |\n");
printf ("| | | | | |\n");
printf ("| 12 48.91mV 4.07mV 292.02mW 24.34mW |\n");
printf ("+------------+------------+------------+------------+------------+\n");
And for now, this is all I got.
#include <stdio.h>
int main ()
{
int circuit;
{
{
printf ("Please enter the type of circuits being tested.\nPlease enter 1 for Serial, 2 for Parallel.\n");
scanf ("%d", &circuit);
}
while (circuit != 1 && circuit != 2)
{
printf ("Invalid input.\n");
printf ("Please re-enter the type of circuits being tested. 1 for Serial, 2 for Parallel.");
scanf ("%d", &circuit);
}
if (circuit==1)
{
printf ("You have chosen: Serial.\n");
}
else
{
printf ("You have chosen: Parallel.\n");
goto parallel;
}
}
{
float current;
float resistor1;
float resistor2;
float resistor3;
printf ("Please enter the current value of the circuit: ");
scanf ("%f", ¤t);
while (current > 500 || current < 5)
{
printf ("Please re-enter the current value: ");
scanf ("%f", ¤t);
}
printf ("Now, enter the first resistor value: ");
scanf ("%f", &resistor1);
printf ("Now, enter the second resistor value (If not applicable, type 0): ");
scanf ("%f", &resistor2);
printf ("Now, enter the third resistor value (If not applicable, type 0): ");
scanf ("%f", &resistor3);
float voltage;
float power;
voltage=current*(resistor1+resistor2+resistor3);
power=current*voltage;
printf ("The voltage of the circuit is %.2fmV.\n", voltage);
printf ("The power of the circuit is %.2fmW.\n", power);
return 0;
}
parallel:
{
float current;
float resistor1;
float resistor2;
float resistor3;
printf ("Please enter the current value of the circuit: ");
scanf ("%f", ¤t);
while (current > 500 || current < 5)
{
printf ("Please re-enter the current value: ");
scanf ("%f", ¤t);
}
printf ("Now, enter the first resistor value: ");
scanf ("%f", &resistor1);
printf ("Now, enter the second resistor value (If not applicable, type 0): ");
scanf ("%f", &resistor2);
printf ("Now, enter the third resistor value (If not applicable, type 0): ");
scanf ("%f", &resistor3);
float voltage;
float power;
if (resistor1 == 0)
{
voltage=current*(1/((1/resistor2)+(1/resistor3)));
power=current*voltage;
printf ("The voltage of the circuit is %.2fmV.\n", voltage);
printf ("The power of the circuit is %.2fmW.\n", power);
}
else if (resistor2 == 0)
{
voltage=current*(1/((1/resistor1)+(1/resistor3)));
power=current*voltage;
printf ("The voltage of the circuit is %.2fmV.\n", voltage);
printf ("The power of the circuit is %.2fmW.\n", power);
}
else if (resistor3 == 0)
{
voltage=current*(1/((1/resistor1)+(1/resistor2)));
power=current*voltage;
printf ("The voltage of the circuit is %.2fmV.\n", voltage);
printf ("The power of the circuit is %.2fmW.\n", power);
}
else
{
voltage=current*(1/((1/resistor1)+(1/resistor2)+(1/resistor3)));
power=current*voltage;
printf ("The voltage of the circuit is %.2fmV.\n", voltage);
printf ("The power of the circuit is %.2fmW.\n", power);
}
return 0;
}
}
This post has been edited by jimblumberg: 12 July 2012 - 01:44 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.

New Topic/Question
Reply



MultiQuote





|