Thread: Help me get this to work please

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    4

    Help me get this to work please

    Help me get this to work please-o-mrkrectw_eqt12ye8wfa-png

    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main()
    
    
    {
    
    
      float r, F, G, m1, m2;
      float gravitationalforce;
    
    
      /*
      * User inputs the distance & mass of the two objects.
      */
    
    
      printf("Enter the mass of the two object 2: ");
      scanf("%f, &m1,");
    
    
      printf("Enter the mass of the object 2: ");
      scanf("%f, &m2");
      
      printf("Enter the distance of the object: ");
      scanf("%f, &r");
    
    
    
    
      /*
      * Distance and mass is inputted.
      */
    
    
      gravitationalforce = 6.674e-11;
    
    
      printf("\nGravitational force : %20f ",F);
    
    
      /*
      * Values inputted provide gravitational force.
      */
    
    
      return(0);
    }
    Not sure how to input the F = G m1*m2 / r^2 part

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Have you worked with arithmetic operators?
    If so, just apply them to the variables as indicated.

    Code:
    // example:
    
    int a = 4;
    int b = 5;
    int product = a * b;
    It might be easier for you to use temporary variables and calculate each piece separately, rather than trying to write out the entire equation in one line.

    Also, you have some syntax errors in your program. It is very helpful to compile and test your code often. For instance, before going any further with the equation, just read the inputs and print them back out, fixing any errors (if present). When that part works, move on to the equation portion of the assignment.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    It appears I misread your question.

    This is wrong:

    Code:
    scanf("%f, &m1,");
    It should look like this:

    Code:
    scanf("%f", &m1);
    Note the location of the quotes and comma.

  4. #4
    Registered User
    Join Date
    Oct 2017
    Posts
    4
    Quote Originally Posted by Matticus View Post
    It appears I misread your question.

    This is wrong:

    Code:
    scanf("%f, &m1,");
    It should look like this:

    Code:
    scanf("%f", &m1);
    Note the location of the quotes and comma.
    I got it working thanks

  5. #5
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Newton's Law program

    Newton's Law program - C++ Forum

    or
    Computational Physics - modelling the two-dimensional gravitational p…

    its in c++ so you'll have to maybe convert it, maybe not. depends
    Last edited by userxbw; 10-05-2017 at 07:49 PM.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    The OP simply has to express the equation in code. There's no need for them to copy and/or convert existing code. We should be encouraging people to solve problems themselves, not offer copy/paste solutions.

  7. #7
    Banned
    Join Date
    Aug 2017
    Posts
    861
    it is not like he cannot learn by example as the post show how tos. if we write it or someone else does, who is to say he will not copy paste whatever it posted in here? it is the same thing, just the source has changed.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by userxbw View Post
    it is not like he cannot learn by example as the post show how tos.
    One learns programming much better by manually typing all of their code, and attempting to solve the problem themselves. "Learning by example" is not beneficial at this stage. They need to try walking all on their own - using a crutch this early on makes it harder to progress.

    Quote Originally Posted by userxbw View Post
    if we write it or someone else does, who is to say he will not copy paste whatever it posted in here?
    That is why we do not provide solutions, or links to complete solutions. It is more helpful to the learning process to guide people towards a solution.

    It's very easy for many of us to write these beginner programs. It's much harder to craft a response that will give the person a push in the right direction without giving away the answer.

  9. #9
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Matticus View Post
    One learns programming much better by manually typing all of their code, and attempting to solve the problem themselves. "Learning by example" is not beneficial at this stage. They need to try walking all on their own - using a crutch this early on makes it harder to progress.



    That is why we do not provide solutions, or links to complete solutions. It is more helpful to the learning process to guide people towards a solution.

    It's very easy for many of us to write these beginner programs. It's much harder to craft a response that will give the person a push in the right direction without giving away the answer.
    helping someone, or just giving that person a solution to their problem as long as one learns that is all that matters. if they cheat
    themselves then they have done just that. someone that is in college better should have leaned that lesson by then.

    if one sees the solution to the problem it too can help one better understand the how to get to it the next time. instead of making that other struggle to no end.

    we are suppose to be making life easier for the other. Not the other way around. people all learn differently, who is to say they cannot learn by examples and seeing solutions to the problem?

    they even put the solution to the problems in the teachers book. they, the powers that be do not make the teacher do all of the work. they instead give them the solutions to what problems they are to give out to the others. therefore by that means even the student can do that part of the teachers job.

    as far as copy and past instead of repetition by typing it out so one will remember what to write. that is called what?

    as far as what I did in here he still have to understand the math behind it, it is all Newton's Law that part does not change. seeing what functions to use to do the math. no telling (showing ) him (someone) what to do so he (they) can see how to do it, nothing wrong with that.

    here just point you to the air plane, tell you how to turn it on, then leave the rest up to you to figure out.

    an inquisitive mind will keep asking questions until he or she has the answers he or she seeks. by hook or crook.
    Last edited by userxbw; 10-06-2017 at 08:41 AM.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by userxbw
    helping someone, or just giving that person a solution to their problem as long as one learns that is all that matters.
    It is not wise to become a homework solution service, and that is more likely to happen when complete answers to what are obviously homework questions are handed out on a plate.

    Quote Originally Posted by userxbw
    if they cheat
    themselves then they have done just that. someone that is in college better should have leaned that lesson by then.
    That is true, but then sometimes it can be difficult to do things substantially differently after seeing a complete solution to a problem, in which case the student would be faced with the dilemma of choosing between plagiarism (minor modifications are insufficient to excuse this) or to continue to try finding a different (and possibly inferior) solution to the homework problem.

    Quote Originally Posted by userxbw
    we are suppose to be making life easier for the other. Not the other way around. people all learn differently, who is to say they cannot learn by examples and seeing solutions to the problem?
    Hence, feel free to post solutions to similiar problems, e.g., a variation of the problem posed such that the student has to understand the solution to come up with a similiar solution to the original problem, or perhaps a simplified version of the original problem to demonstrate some critical idea in the problem solving method. It may also help if you explained in prose the ideas behind your solution to the alternative problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does this work?
    By sammythesp3rmy in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2013, 04:47 PM
  2. Can't work this out...
    By MrSandwich in forum C Programming
    Replies: 5
    Last Post: 01-07-2011, 12:51 AM
  3. How does this work?
    By Memloop in forum C Programming
    Replies: 8
    Last Post: 04-13-2010, 03:11 PM
  4. work?
    By taurus in forum C Programming
    Replies: 12
    Last Post: 10-17-2007, 12:47 PM
  5. my function doesn't work! it should work
    By Unregistered in forum C Programming
    Replies: 13
    Last Post: 05-02-2002, 02:53 PM

Tags for this Thread