January 27th, 2010, 11:49 AM

Simple c programming assignment help!
I have to enter all of these equations into one program using windows visual studios I am just having some trouble cause I am new to this stuff. Please help!!!
Ohm's Law: V = IR, where V is the voltage, I is the current, and R is the resistance of the circuit (all values are integers)
Joule's Law: P = (V^2) / R, where P is the power, V is the voltage, and R is the resistance of the circuit (all values are integers). Do we have loss of precision? What kind of division is being performed?
third order polynomial equation: y = 3 * ax3 + (1/4) * bx2 + 10 * cx + (5) * d (x, y, a, b, c, and d are integer numbers). Be careful here! What is (1 / 4) as an integer result? We do not want integer division in this case! How do we fix it? Do we ultimately have loss of precision? Remember this problem for the equations below!!! Please think about these questions, however, you do not have to formally answer them in your program!
circumference of a circle: circumference = 2 * PI * radius (circumference and radius are floatingpoint numbers; PI should be defined as a constant floatingpoint number and should not be entered by the user)
volume of a cone: volume_cone = 1/3 * PI * radius2 * height (volume_cone, radius, and height are floatingpoint numbers; PI should be defined as a constant floatingpoint number and should not be entered by the user)
surface area of a cylinder: area_cylinder = 2 * PI * radius2 + 2 * PI * radius * height (area_cylinder, radius, and height are floatingpoint numbers; PI should be defined as a constant floatingpoint number and should not be entered by the user)
general equation: y = 1/7 * x  (5.5) * z + a % (3 * b) (x, y, and z are floatingpoint numbers; a and b are integer numbers).
As each equation is evaluated the equation along with the result should be displayed on the screen.
thanks for any and all help!
January 27th, 2010, 11:54 AM

I think you misunderstood this forum. We don't do homework here. We discuss and educate people who have problems, which they have tried genuinely to solve.
When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.
Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
January 27th, 2010, 11:56 AM

ok well what about a specific question? After I enter one equation with print f and scan f and stuff how do I make it so it just goes right into the next equation without starting over?
January 27th, 2010, 12:01 PM

You have a system for entering an equation. Repeat it as necessary.
For example, if you want to print hello world on screen once, what do you do? You might make a call to puts with "Hello world" as the argument. You want to do it twice. What do you? Make another call to puts with the same argument. You want to do so repeatedly, for say, 100 times. There are looping constructs like for loops and while loops to help you construct this repetition.
When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.
Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
January 27th, 2010, 03:20 PM

Originally Posted by Oler1s
You have a system for entering an equation. Repeat it as necessary.
For example, if you want to print hello world on screen once, what do you do? You might make a call to puts with "Hello world" as the argument. You want to do it twice. What do you? Make another call to puts with the same argument. You want to do so repeatedly, for say, 100 times. There are looping constructs like for loops and while loops to help you construct this repetition.
Ok that makes sense. I am confused though by how you enter the actual values into scan f and then at the end of the program to actually perform the equation. for example I have tried several variations of this and still get errors
/*
*performs the equation of Ohm's Law
*/
#include <stdio.h>
int main (void)
{
V, //voltage  output
I, // current  input
R, // resistance  input
/*Get the I and R values */
printf ("please enter 2 values (I and R) for use in Ohm's Law>");
scanf("%d", &I),("&d", &R);
/*calculate the equation V=I*R */
V=I*R;
/*Display the formulated equation V=I*R*/
printf("Ohm's Law: V=I*R=%fI*%fR, V);
return (0);
so the part i am confused by is the %d and then using this to display the equation. What am I doing wrong? Im not looking for answers I just want to understand. Thanks
January 27th, 2010, 03:56 PM

Here is an example that uses printf and scanf that you can use to work off of:
c Code:
#include <stdio.h>
#include <math.h>
int main(){
double a=0,b=0,c=0;
int n=0;
printf("Pythagorean Theorem calculator\n");
printf("Equation is a*a + b*b = c*c\n");
printf("Please enter A and B, separated by a space:");
n=scanf("%lf %lf", &a, &b);
while (n != 2){
char c;
do {
c=getchar();
} while (c != EOF && c != '\n');
printf("Error in input, try again\n");
printf("Please enter A and B, separated by a space:");
n=scanf("%lf %lf", &a, &b);
}
c = sqrt((a*a)+(b*b));
printf("Solution: sqrt((%lf*%lf) + (%lf+%lf)) = c = %lf", a, a, b, b, c);
return 0;
}
If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
January 27th, 2010, 05:15 PM

ok thanks but what do i use instead of return (0) to keep going with the other equations i need. I tried return (0) and I get these errors
e:\pa 1\pa 1\assignment1.c(46) : error C2143: syntax error : missing ';' before 'type'
January 27th, 2010, 05:43 PM

Post the code and the entire build log. Use code tags when you post code.
I no longer wish to be associated with this site.
July 17th, 2017, 02:35 PM

Programming Help
Originally Posted by Oler1s
I think you misunderstood this forum. We don't do homework here. We discuss and educate people who have problems, which they have tried genuinely to solve.
That is absolutely correct. Forums like this are meant for information sharing purposes & knowing the full know how of the problem is absolutely necessary for that. Otherwise one could simply use service of online assignment help.