449,314 Members | 1,775 Online
Need help? Post your question and get tips & solutions from a community of 449,314 IT Pros & Developers. It's quick & easy.

# First program

 P: n/a Thanks to everyone that has helped me. Now I'm trying to write my first program. I have an example of one that I need to write about. Any help getting me started is appreciated. I'm having trouble getting my compiler to work, access to my a drive is denied, anyone know why this is? Ok here is the info for my program: The two laws of electricity are used in this program. Law #1 The first is Ohm's Law which relates voltage, curret, and resistence: V=I * R or I=V / R or R= V / I Where V= The voltage across the resistor measured in volts. I= The current passing through the resistor measured in amperes. R= The value of the resistance measured in ohms. Law #2 The second is Kirchhoff's Voltage Law which relates the sum of voltages around a closed loop. This law will be shown in two forms as it applies to the programming problem. Form 1) VS =V1 + V2 + V3 VS - V1 - V2 - V3 = 0 Where VS= The voltage source measured in volts. V1= The voltage across resistor R1. V2= The voltage across resistor R2. V3= The voltage across resistor R3. Form2) RT = R1 + R2 + R3 Where RT= The sum of resistors in a series connection. R!,R2,R3 = The value of the resistence measured in ohms. The input section of the program will use the scanf() function to give variables VS,R1,R2, and R3 their initial values. R1, R2, and R3 are the integer variables while the VS variable must be of type float. The calculation section will follow this pattern: Step 1) Add up the resistor values RT=R1 + R2 + R3. Step 2) If RT is zero ( print and use return 0; statement to quit the program) else Calculate total current using Ohm's Law. IT = VS / RT Step 3) Calculate V1, V2, V3 using Ohm's Law. V1= IT * R1, V2= IT * R2, V3 = IT * R3 Step 4) Calculate CALLER, which by Kirchhoff's law should equal zero. When the float variables are used, there can be loss in the accuracy because of the way numbers are stored in the computer. Make sure thath the variable CALLER is a float. CALLER = VS - V1 - V2 - V3 The output section will print to the screen V1, V2, V3 and CALLER using the print() function. Thanks again! Jan 24 '06 #1
5 Replies