Thread: Slope Formula

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

    Slope Formula

    Can anyone see what is the problem here?

    I am getting the message:

    C:\DEV-C_~1\LIB\\libmingw32.a(main.o)(.text+0x8e): undefined reference to `WinMain@16'

    And i am useing Dev-C++

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

    #include <stdio.h>
    Main()

    {

    int x1, x2, y1, y2, m ;

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

    printf ( "in the form (x,y) the first point \n" ) ;
    scanf ( "%fd%fd" ,&x1 ,&y1 ) ;

    printf ( "In the form (x,y) the second point \n" ) ;
    scanf ( "%fd%fd" ,&x2 ,&y2 ) ;

    m = (y1 - y2) / (x1 - x2);

    getch ();

    }

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

    Note: i am still new and this seems hard to me.

    thanx,

    Dave.
    Dangerous Dave

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Main()
    it should be main (it's case sensitive)

    > C:\DEV-C_~1\LIB\\libmingw32.a(main.o)(.text+0x8e): undefined reference to `WinMain@16'
    This means you've tried to compile a windows (GUI) program, whereas you are actually creating a console (command line / DOS box) program.

    Look through the project settings to see what type of program you are creating.
    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.

  3. #3
    Unregistered
    Guest
    I spotted 4 errors

    1. no header file for getch() should be <conio.h>

    2.no return type for main() in this case should be void

    3. you have spelt main with a capital M

    4. in the scanf() you have %fd try removing it

    after these 4 changes it worked

  4. #4
    Unregistered
    Guest
    above error 4.
    I should have been more specific just remove the f from the scanf's

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    44
    I have changed the source with regards to your sugestions try this and tell me what u think.

    ---------------------------------------------------------------------------------
    #include <stdio.h>
    #include <conio.h>
    main()
    {
    int x1, y1, x2, y2, m ;

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

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

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

    m = ( y2 - y1 ) / (x2 - x1) ;

    printf ( "The slope is %d \n" ,m ) ;

    getch () ;
    }
    ---------------------------------------------------------------------------------

    thanks,

    Dave.
    Dangerous Dave

  6. #6
    Unregistered
    Guest
    That code works on my compiler except that there is no return type for main() : should be void.
    It might be an idea to put in a printf() at the end so you can see your results

  7. #7
    Unregistered
    Guest
    DOH DOH you have put a printf in I should open my eyes more often sorry

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    44
    what do you mean there is no return type for main() : should be void? i am new to this and i am confused by what u are saying please explaine.
    Dangerous Dave

  9. #9
    Unregistered
    Guest
    main is a function like any other and the compiler needs to be told what to expect, in your case it should read :
    void main() as you are returning no values to the calling routine. Your program will still work but your compiler should give you a warning. I't is better to be explicit in all your coding as this will ensure compatibility with other systems.


    Happy coding

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 04:31 AM
  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. Finished Slope Formula
    By Dangerous Dave in forum C Programming
    Replies: 2
    Last Post: 10-08-2001, 12:06 PM
  5. Revised Slope formula
    By Dangerous Dave in forum C Programming
    Replies: 3
    Last Post: 10-07-2001, 10:37 PM