Finished Slope Formula

This is a discussion on Finished Slope Formula within the C Programming forums, part of the General Programming Boards category; Thank u everyone that helped me. Here is the finished source code. ---------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> main() { float ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    44

    Finished Slope Formula

    Thank u everyone that helped me. Here is the finished source code.

    ----------------------------------------------------------------------------

    #include <stdio.h>
    #include <stdlib.h>

    main()
    {
    float x1, y1, x2, y2, m ;
    float X , Y ;

    printf ( "To find the slope of your line enter the following: \n\n" ) ;

    printf ( "The First set of points. eg. (x,y) \n" ) ;
    printf ( "x: \n" ) ;
    scanf ( "%f" , &x1 ) ;
    printf ( "y: \n" ) ;
    scanf ( "%f" , &y1 ) ;

    printf ( "The Second set of points. eg. (x,y) \n" ) ;
    printf ( "x: \n" ) ;
    scanf ( "%f" , &x2 ) ;
    printf ( "y: \n" ) ;
    scanf ( "%f" , &y2 ) ;

    Y = y2 - y1 ;
    X = x2 - x1 ;
    m = Y / X ;

    printf ( "\nThe slope of the line is: %f " , m) ;
    printf ( "\n\n" ) ;
    system("PAUSE");

    }
    ---------------------------------------------------------------------------

    I have a few more questions, try the program and when u get your answey it will be form (eg.) 2.000000. How would i go about shortening this to 2.0?

    And if 4 numbers are entered which are equal how would i desplay an error message telling the user to start again?
    Dangerous Dave

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    34

    to shorten a double or float

    in your print statement go
    printf("%2.2lf, int);

    after the percent sign you will enter the digits before and after the decimal that you want.

    hope this helps.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > How would i go about shortening this to 2.0?
    Example
    printf( "%.1f\n", 1234.5678 );

    > And if 4 numbers are entered which are equal how would i desplay an
    Code:
    do {
        // all your prompt and input code
    } while ( (x1 == x2) && (y1 == y2) );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zeller's Formula
    By unejam2005 in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2005, 08:48 PM
  2. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM
  3. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM
  4. Slope Formula
    By Dangerous Dave in forum C Programming
    Replies: 9
    Last Post: 10-08-2001, 12:25 PM
  5. Revised Slope formula
    By Dangerous Dave in forum C Programming
    Replies: 3
    Last Post: 10-07-2001, 10:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21