473,325 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

First program

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
5 5378
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
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
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
"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
cj
Thanks for your comments and help!

Jan 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Pieter Provoost | last post by:
Hi, I just made my first c++ program, and I would like to know if there are things I can do better. Also, the exe is about 500 kb, can I make it smaller? Thanks! Pieter
2
by: John | last post by:
I'm trying to build my first program using Visual C++ V6 and I have a build error. It's got to be something to do with main() but I can't see what. Can someone give me a clue as to which library I...
26
by: mwt | last post by:
Hello. Today I wrote my first program in C. It adds up the elements in an array. I am just beginning to learn this language. Any tips or pointers about better ways to write/structure/format/etc....
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
3
by: Jason Taylor | last post by:
I am wanting to learn C++, and am curious what my first program should be. I learned PHP by reading the docs as I wrote a news posting script. Any ideas on how I would go about starting my trek in...
3
by: cs | last post by:
Hi, I'm new to C and would appreciate any feedback on the following program, asplit, which splits a file into 2 new files, putting a certain number of lines in the first file, and all the rest...
36
Parul Bagadia
by: Parul Bagadia | last post by:
Hi people..... this is my first program in VB. Before this i have done programming in C,C++. I read some of the chapters from Black book of VB; but still having problem in the initial part itself....
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.