#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    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 floating-point numbers; PI should be defined as a constant floating-point 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 floating-point numbers; PI should be defined as a constant floating-point 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 floating-point numbers; PI should be defined as a constant floating-point 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 floating-point 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!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,254
    Rep Power
    1740
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0
    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?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,254
    Rep Power
    1740
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0
    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
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,124
    Rep Power
    4103
    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;
    }
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0
    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'
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    890
    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.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    1
    Rep Power
    0

    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.

IMN logo majestic logo threadwatch logo seochat tools logo