11-11-2009, 03:23 PM
I am using Microsoft Visual Studio. i'm having trouble with one part.
#include <stdio.h>
the output is supposed to be like this
Enter the values of the 3 resistances: 30 10 20
Enter the value of voltage: 2.0
Voltage = 2.0 V
Equivalent resistance = 36.666666 ohm
Current = 0.05454545 A
the underlined values are to be entered by the user (meaning i enter 30 10 20 for the 3 resistances).
ok problem lies at the "entering values of 3 resistances" and the printf & scanf for that part. the output after compiling it is different from the supposed output, after i enter the 3 resistances 30 10 20.
#include <stdio.h>
Code:
void main(void)
{
float r1, r2, r3, V, I, R;
/* input */
printf("Enter the value of the 3 resistances: ");
scanf("%f %f %f", &r1 &r2 &r3);
printf("Enter the value of voltage: ");
scanf("%f", &V);
/* calculate the equivalent resistance */
R = r1 + (1 / (1 / r2 + 1 / r3) );
/* calculate the current */
I = V / R;
/* output */
printf("Voltage = %fV\n", V);
printf("Equivalent resistance = %f ohm\n", R);
printf("Current = %f A", I);
} // end mainEnter the values of the 3 resistances: 30 10 20
Enter the value of voltage: 2.0
Voltage = 2.0 V
Equivalent resistance = 36.666666 ohm
Current = 0.05454545 A
the underlined values are to be entered by the user (meaning i enter 30 10 20 for the 3 resistances).
ok problem lies at the "entering values of 3 resistances" and the printf & scanf for that part. the output after compiling it is different from the supposed output, after i enter the 3 resistances 30 10 20.