Thread: unable to run program

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    7

    unable to run program

    I have following code & i am using Turbo C++ 3.0. I am unable to run this program. Please help me

    Code:
    main ()
    { 
        int a, b, c;
    
        a = 5;
        b = 10;
        c = mul (a,b);
    
        printf (“multiplication of %d and %d is %d”,a,b,c);
    }
    int mul (int x, int y)
    int p;
    
    p = x*y;
        {
    return(p);
        }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Can you run "hello world"? That's the program to start with when trying a new compiler. Never tried Turbo C++ 3.0, isnt that program from the 90s or something.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("Hello, world!\n");
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Have you bothered to read the error messages from your compiler? Even an antique compiler like TC++3 will give you sensible diagnostics on that code.

    The curly braces associated with the mul() function are misplaced. In C++, it is necessary to specify that main() returns int (a C compiler lets you get away not doing that, a C++ compiler does not), and it is necessary to #include <stdio.h> in order to use printf(). And the function mul() needs to be declared (a "prototype" as a minimum) before code that calls it.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by c99tutorial View Post
    Never tried Turbo C++ 3.0, isnt that program from the 90s or something.
    1991.

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by grumpy View Post
    Have you bothered to read the error messages from your compiler? Even an antique compiler like TC++3 will give you sensible diagnostics on that code.
    The characters “ and ” are invalid in C source anyway. Doesn't matter if the current trend is to use 4000-year-old compilers. Actually, I think that 4000 years ago those characters weren't even thought of anyway.

  6. #6
    Registered User
    Join Date
    Nov 2013
    Posts
    7
    Quote Originally Posted by grumpy View Post
    Have you bothered to read the error messages from your compiler? Even an antique compiler like TC++3 will give you sensible diagnostics on that code.

    The curly braces associated with the mul() function are misplaced. In C++, it is necessary to specify that main() returns int (a C compiler lets you get away not doing that, a C++ compiler does not), and it is necessary to #include <stdio.h> in order to use printf(). And the function mul() needs to be declared (a "prototype" as a minimum) before code that calls it.
    how to use prototype in mul() function? please help

  7. #7
    Registered User
    Join Date
    Nov 2013
    Posts
    7
    Quote Originally Posted by c99tutorial View Post
    Can you run "hello world"? That's the program to start with when trying a new compiler. Never tried Turbo C++ 3.0, isnt that program from the 90s or something.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("Hello, world!\n");
        return 0;
    }
    i can run this code correctly. what compiler you are using? please tell me.

  8. #8
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by Arunjib Roy View Post
    how to use prototype in mul() function? please help
    I found a website with some suggestions for this, maaybe you can take a look and try some of them out

    https://www.google.com/search?q=c+function+prototype+example

  9. #9
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Arunjib Roy View Post
    how to use prototype in mul() function? please help
    Get a modern compiler and insist that your "school" doesn't use Turbo C.

    But if you're adamant:

    Code:
    #include <STDIO.H>
    
    mul(x, y);
    
    void main (void)
    { 
        int a;
        int b;
        int c;
    
        a = 5;
        b = 10;
        c = mul (a,b);
    
        printf ("multiplication of %d and %d is %d",a,b,c);
    }
    
    mul(x, y)
       int x;
       int y;
    {
        int p;
    
        p = x*y;
        
        return ((p));
    }

  10. #10
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by Arunjib Roy View Post
    i can run this code correctly. what compiler you are using? please tell me.
    I use gcc 4.8. For Windows you can download MinGW which provides this. A lot of other projects also bundle it like Code::Blocks and Qt Creator. Why don't you try those out if you want a nicer development environment than a DOS window.

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Hodor View Post
    The characters “ and ” are invalid in C source anyway.
    In a string literal, they are valid.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  12. #12
    Registered User
    Join Date
    Nov 2013
    Posts
    7
    Quote Originally Posted by Hodor View Post
    Get a modern compiler and insist that your "school" doesn't use Turbo C.

    But if you're adamant:

    Code:
    #include <STDIO.H>
    
    mul(x, y);
    
    void main (void)
    { 
        int a;
        int b;
        int c;
    
        a = 5;
        b = 10;
        c = mul (a,b);
    
        printf ("multiplication of %d and %d is %d",a,b,c);
    }
    
    mul(x, y)
       int x;
       int y;
    {
        int p;
    
        p = x*y;
        
        return ((p));
    }
    getting error msgs:

    Line 3: Style of function definition is now obsolete
    Line 3: Declaration was expected
    Line 6: 'main' is not a parameter
    Line 6: , expected

  13. #13
    Registered User
    Join Date
    Nov 2013
    Posts
    7
    Quote Originally Posted by c99tutorial View Post
    I use gcc 4.8. For Windows you can download MinGW which provides this. A lot of other projects also bundle it like Code::Blocks and Qt Creator. Why don't you try those out if you want a nicer development environment than a DOS window.
    Actually i don't knw how to use those Windows version compilers. thats why i cannot use those though i want to do

  14. #14
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by Arunjib Roy View Post
    Actually i don't knw how to use those Windows version compilers. thats why i cannot use those though i want to do
    There are installation instructions on the websites. It's basically the same as installing any other Windows program.

  15. #15
    Registered User
    Join Date
    Nov 2013
    Location
    Silicon Valley, CA
    Posts
    7
    For a beginner, Bloodshot Dev C++ is better. Well, I've never tried Turbo C++, so I can't judge.


    GCC compiler like MinGW(Windows) is great. The only reason I got it is because there is no GUI support in Visual Studio Express.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unable to execute my program in borland c
    By AkaneNatsumi in forum C Programming
    Replies: 4
    Last Post: 04-25-2013, 01:58 AM
  2. Unable to pause program
    By shacko in forum C++ Programming
    Replies: 5
    Last Post: 01-28-2012, 11:00 AM
  3. Replies: 5
    Last Post: 12-05-2011, 05:07 PM
  4. Program unable to print anything
    By SasDutta in forum C Programming
    Replies: 7
    Last Post: 07-23-2010, 10:04 AM
  5. unable to get simple program working
    By toom in forum Linux Programming
    Replies: 1
    Last Post: 10-11-2003, 05:05 AM

Tags for this Thread