Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can you compile with this code?

    I mean using Dev C++ Bloodshed?

    Code:
    #include<iostream.h>
    int print_candy_gumballs_extra_from_cupons(int c)
    
    {
    
    if(c<0)
    
    {
    
    cout<<"Can' b -ve";
    
    return -1;
    
    }
    
    cout<<c<<" coupons --) ";
    
    cout<<c/10<<" candy bar,";
    
    c=c&#37;10;
    
    cout<<c/3<<" gumball,";
    
    c=c%3;
    
    cout<<c<<" extra coupons\n";
    
     
    
    return 0;
    
    }
    
    main(){
    
    int cupons;
    
    print_candy_gumballs_extra_from_cupons(5);
    
    print_candy_gumballs_extra_from_cupons(52);
    
    print_candy_gumballs_extra_from_cupons(126);
    
    return 0;
    
    }
    
    /*
    
    Output will be
    
    5 coupons --) 0 candy bar,1 gumball,2 extra coupons
    
    52 coupons --) 5 candy bar,0 gumball,2 extra coupons
    
    126 coupons --) 12 candy bar,2 gumball,0 extra coupons
    
    */
    Last edited by oracleguy; 09-02-2008 at 02:30 AM. Reason: Please use the code tags in the future

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Couldn't you just try it yourself?

    I don't have this Bloodshed thing, but it makes it through gcc compilation with a few warnings:

    Code:
    In file included from /usr/include/c++/4.1.3/backward/iostream.h:31,
                     from ./foo.cpp:1:
    /usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
    ./foo.cpp:34: warning: ISO C++ forbids declaration of ‘main’ with no type
    ./foo.cpp: In function ‘int main()’:
    ./foo.cpp:36: warning: unused variable ‘cupons’

  • #3
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    Yes, it compiles fine using Dev C++ 4.9.9.2.

    I don't claim to know my c++ (or compilers) but I was a little surprised to find that you could declare main() without a return type (including void) and still return an int. I guess the compiler just assumes if no return type is declared then the return type is an int.
    Last edited by Gox; 09-02-2008 at 10:33 PM. Reason: Grammar / Spelling

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Gox View Post
    Yes, it compiles fine using Dev C++ 4.9.9.2.

    I don't claim to know my c++ (or compilers) but I was a little surprised to fine that you could declare main() without a return type (including void) and still return an int. I guess the compiler just assumes if no return type is declared then the return type is an int.
    Yeah that is exactly what it does, if no return type is specified the default is int. However you should still always specify the return type which is why most compilers throw out a warning if you don't.
    OracleGuy

  • #5
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by oracleguy View Post
    Yeah that is exactly what it does, if no return type is specified the default is int. However you should still always specify the return type which is why most compilers throw out a warning if you don't.
    I guess if I'd read the post above mine a little more carefully I would have noticed the warning produced for this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •