By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,314 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
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
cj
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 <error message> 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
Share this Question
Share on Google+
5 Replies


P: n/a
cj wrote:
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.
I'm sure it's exciting!
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.
To answer the only question in the post: no we don't know why your
compiler doesn't work, and about the access to your drive please ask
your administrator. Neither is topical in c.l.c.

<snipped homework assignment waffle>
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
Now, I love this bit! A nice warning that using float may lead to loss
of precision, followed by specifying that float is to be used. I hope
the teacher is a CS, and not EE graduate. ;-)
float. CALLER = VS - V1 - V2 - V3 The output section will print to
the screen V1, V2, V3 and CALLER using the print() function.
Good luck with your homework, but I must say it's nothing to write
(home) about. And also: where's the program in all this.

Thanks again!


You're welcome.

Cheers

Vladimir

--
"I went to the museum where they had all the heads and arms from the
statues that are in all the other museums."
-- Steven Wright

Jan 24 '06 #2

P: n/a
cj wrote:
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.
what have you got so far?

<snip>
The input section of the program will use the scanf() function


scanf() is difficult to use correctly. I'd recomend fgets() followed by
sscanf().

<snip>

well first sort out your compiler problems then write your program.
If you run into trouble then ask here.
--
Nick Keighley

Jan 24 '06 #3

P: n/a
cj wrote:
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 <error message> 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.


Recommended reading:

http://www.catb.org/~esr/faqs/smart-questions.html
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Jan 24 '06 #4

P: n/a
"cj" writes:
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 <error message> 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.


Without a compiler you are dead in the water. Solve that problem first,
then try to write the program described above. I don't see the lack of an
A: drive as a current problem. You don't mention where you are having a
problem with the programming. The instructor has already told you a lot
(some of it not very good advice, but that's life.) For example:

o never use scanf()
o never use float unless there is a darn good reason.
o return of 0 means exit sucess, not exit failure as specified above
o most C programmer's detest upper case variable names. They are harder to
type and they look ugly besides.
o there is no print function. There is a printf function.

But it's hard to follow two sets of rules and the instructor is the one who
is going to give you a grade. And you can still produce what he wants so
what the hey.

Here's a start.

#include <stdio.h> /* for scanf*/

int main()
{
int R1, R2, R3;
float VS;
scanf ( /* stuff missing*/);
/* more stuff missing. perhaps 10-15 lines of code */
return 0;
}
Jan 24 '06 #5

P: n/a
cj
Thanks for your comments and help!

Jan 25 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.