Like Tree2Likes
  • 2 Post By Elkvis

HELP!!! DEV C++ users

This is a discussion on HELP!!! DEV C++ users within the C++ Programming forums, part of the General Programming Boards category; not able to compile the simplest code i.e. of hello world the code is Code: #include<iostream> using namespace std; int ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    103

    Unhappy HELP!!! DEV C++ users

    not able to compile the simplest code i.e. of hello world
    the code is
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
            cout<<"hello world!!!";
            return 0;
    }
    the error was
    collect2.exe: error: ld returned 1 exit status
    Last edited by Mukul Kumar; 04-16-2013 at 09:07 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,709
    So what kind of errors are you getting?

    What compiler are you trying to use?

    When you downloaded the IDE did you also download a compiler?

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i m using DEV C++ editor which comes with MinGW GCC 4.7.2 32-bit compiler
    i actually was making a game something like a tournament in which we fight different people and then upgrade ourselves after each fight but its still incomplete
    and we can have test run
    but when i run it i face only one error i.e.
    collect2.exe: error: ld returned 1 exit status
    and also when i use borland C++ compiler then i face no errors
    then i made a simple program of hello world and i still got same error in DEV C++!!!
    Code:
    #include<iostream>
    #include<conio.h>
    #include<time.h>
    #include<stdlib.h>
    #include<stdio.h>
    #include<dos.h>
    using namespace std;
    struct player{
        int health,armour,damage[2],money;
        char name[10];
    }p;
    struct rat{
        int health,armour,damage[2],money;
    }rat1;
    
    int main();
    void tutorial();
    void options();
    void shop();
    void quit();
    void weapons();
    void armour();
    void extras();
    
    
    void start(void)
    {
        system("cls");
        cout<<"when you are ready press enter...";
        getch();
        
    }
    void tutorial(void)
    {
        system("cls");
        cout<<"learn how to play this game...\npress any key to continue.";
        getch();
        cout<<"dsfsfw";
    }
    void options(void)
    {
        system("cls");
    }
    void shop()
    {
    
        back:
        int b=1;
        system("cls");
        cout<<"\nwelcome to the shop";
        cout<<"press...\n (1) to buy weapons\n (2) to buy armour\n (3) to buy extras\n (4) back";
        char a=getch();
        switch(a)
        {
            case '1':weapons();break;
            case '2':armour();break;
            case '3':extras();break;
            case '4':b=0;break;
        }
        if(b)
        {
            system("cls");
            goto back;
        }
    }
    void weapons()
    {
        cout<<"choose...\n(1) light weapons \n(2) medium weapons\n(3) heavy weapons";
        int a;
        cin>>a;
        switch(a)
        {
            case 1:{
                
                cout<<"light weapons press...\n (1) small stick (cost 10 damage : 0-3)\n (2) twig (cost 15 damage : 2-5)\n (3) sharp bamboo spear (cost 20 damage : 5-10)\n (4) rusty sword (cost 30 damage : 10-20)\n (5) iron sword (cost 40 damage : 15-25)";
                cin>>a;
                switch(a)
                {
                    case 1:{
                        p.damage[0]=0;
                        p.damage[1]=3;
                        p.money-=10;
                    }break;
                    case 2:{
                        p.damage[0]=2;
                        p.damage[1]=5;
                        p.money-=15;
                    }break;
                    case 3:{
                        p.damage[0]=5;
                        p.damage[1]=10;
                        p.money-=20;
                    }break;
                    case 4:{
                        p.damage[0]=10;
                        p.damage[1]=20;
                        p.money-=30;
                    }break;
                    case 5:{
                        p.damage[0]=15;
                        p.damage[1]=25;
                        p.money-=40;
                    }break;
                    case 6:system("cls");break;
                }
            }break;
            case 2:
            {
                cout<<"\nmedium weapons press...\n (1) medium sword (cost 50 damage : 20-30)\n (2) medium iron sword(cost 60 damage : 20-35)\n (3) sharp sword(cost 80 damage : 40-60)\n (4) sharp long sword (cost 100 damage : 50-100)\n (5) double sword(cost 120 damage : 60-100)\n (6) back";
                cin>>a;
                switch(a)
                {
                    case 1:{
                        p.damage[0]=20;
                        p.damage[1]=30;
                        p.money-=50;
                    }break;
                    case 2:{
                        p.damage[0]=20;
                        p.damage[1]=35;
                        p.money-=60;
                    }break;
                    case 3:{
                        p.damage[0]=40;
                        p.damage[1]=60;
                        p.money-=80;
                    }break;
                    case 4:{
                        p.damage[0]=50;
                        p.damage[1]=100;
                        p.money-=100;
                    }break;
                    case 5:{
                        p.damage[0]=60;
                        p.damage[1]=100;
                        p.money-=120;
                    }break;
                    case 6:system("cls");break;
                }
            }break;
            case 3:
            {
            cout<<"heavy weapons press...\n (12) silver sword (cost 125 damage : 65-100)\n (13) golden sword(cost 150 damage : 80-120)\n (3) diamond tipped sword(cost 180 damage : 100-200)\n (4) diamond sword (cost 200 damage : 150-250)\n (5) the sword of death(cost 300 damage : 500-600)\n (6) back";
            cin>>a;
                switch(a)
                {
                    case 1:{
                        p.damage[0]=65;
                        p.damage[1]=100;
                        p.money-=125;
                    }break;
                    case 2:{
                        p.damage[0]=80;
                        p.damage[1]=120;
                        p.money-=150;
                    }break;
                    case 3:{
                        p.damage[0]=100;
                        p.damage[1]=200;
                        p.money-=180;
                    }break;
                    case 4:{
                        p.damage[0]=150;
                        p.damage[1]=250;
                        p.money-=200;
                    }break;
                    case 5:{
                        p.damage[0]=500;
                        p.damage[1]=600;
                        p.money-=300;
                    }break;
                    case 6:system("cls");break;
                }
            }break;
        }
    }
    void quit(void)
    {
        system("cls");
    }
    void back()
    {
        system("cls");
    }
    
    int main()
    {
        system("cls");
        char a;
        cout<<"welcome to 'the tournament'\n";
        cout<<"press...\n (1) to start\n (2) for tutorial\n (3) for options\n (4) to quit";
        a=getch();
        switch(a)
        {
            case '1':start();break;
            case '2':tutorial();break;
            case '3':options();break;
            case '4':quit();break;
        }
        return 0;
    }
    Last edited by Mukul Kumar; 04-16-2013 at 09:30 AM.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,287
    Verify: (1) the source file is properly included in the project, and (2) the source file has the correct file extension.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    2,709
    Also what is this?
    Code:
     
    int main();
    The function main() doesn't need a prototype.

    Where did you implement your armour() and extras() functions?

    Why are you including the <dos.h> header file? It's a "little" outdated and shouldn't really be used with today's modern operating systems.

    Also if you're writing a C++ program you should be using the C++ standard headers not their C versions, <cstdio> instead of <stdio.h>. And since you're not actually using anything in these C headers you shouldn't be including them anyway.

    Jim

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i already explained that this is incomplete executable code fragment also i need these standard library functions because i know only this much and still learning + i feel an ease to use these function
    i will use the function delay(double) from the header file dos.h
    and about the prototyping of main function i need that in the function ask() where i will ask the user to rerun this code if yes then i'll call the function main()
    also i face no errors in borland C++ editor!!!
    till i get the solution i'll continue my work in borland C++ editor
    Last edited by Mukul Kumar; 04-16-2013 at 10:41 AM.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    2,287
    Here's some extra punctuation of mine that you can have to make your messages more clear:

    ......,,,,,,

    You shouldn't be calling main from another function. Instead, you should have a loop in main that cycles or breaks based on the return value of "ask()".

    As to the problem at hand, did you check the things I mentioned in post #4?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by Mukul Kumar
    and about the prototyping of main function i need that in the function ask() where i will ask the user to rerun this code if yes then i'll call the function main()
    It is not permitted to use the global main function in your program. Therefore, you are not allowed to call it. Luckily, there is an alternative: have the main function call the function (possibly indirectly) in a loop instead.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    2,709
    and about the prototyping of main function i need that in the function ask() where i will ask the user to rerun this code if yes then i'll call the function main()
    Since this is a C++ program this doesn't make any sense. In a C++ program main() can't be called by any function, including main(). And even in a C program calling main() is considered a very very bad practice.

    i already explained that this is incomplete code fragment
    So then what is your problem? Incomplete code fragments rarely compile if you haven't at least implemented "stub" functions (functions with blank bodies).


    Jim

  10. #10
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    see the problem is ......that i was verifying time and again to check the working of the code properly and suddenly i faced this problem hence i say it is 100% executable(i tried this in turbo C++) and I AM WORKING ON THOSE FUNCTIONS HAVING NOTHING!!!

  11. #11
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    thanks i will take care of this in future @laserlight,matticus&jimblumberg about that calling of main()
    Last edited by Mukul Kumar; 04-16-2013 at 10:50 AM.

  12. #12
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    now i may not reply for 20 hrs because this is the time in one day when i sit on computer and work + its 10:23 PM here in my country and i m gonna goto sleep so good-night!!!
    i promise i'll work hard on this code

  13. #13
    Registered User
    Join Date
    Oct 2006
    Posts
    2,364
    Quote Originally Posted by Mukul Kumar View Post
    and also when i use borland C++ compiler then i face no errors
    Borland C++ and Turbo C++ are both garbage. They do not support the standard C++ language. Don't ever use them.

    Quote Originally Posted by Mukul Kumar View Post
    Code:
    #include<conio.h>
    #include<dos.h>
    Don't use these headers, as they are not standard, and almost certainly will not work in Dev C++. this goes for the getch() function as well.

    Quote Originally Posted by Mukul Kumar View Post
    Code:
    goto back;
    Don't use goto. it is incredibly bad practice, and you can use a simple while loop to do what you're trying to do here.
    Salem and Elysia like this.

  14. #14
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i found the problem its not in my incomplete code,not even in my bad habits it was in my editor my naughty bro disturbed some settings(i don't know which one) and i set everything to default by reinstalling the editor but thanks to all of you for telling me about my bad habits i'll take care

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Any QT users out there - on a Mac?
    By Dino in forum C++ Programming
    Replies: 9
    Last Post: 09-29-2009, 07:00 PM
  2. Network Users
    By Traveller in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-20-2004, 02:40 PM
  3. Users
    By Quantrizi in forum Linux Programming
    Replies: 0
    Last Post: 08-02-2002, 11:12 AM
  4. UK Users
    By iain in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-15-2002, 01:03 AM
  5. users
    By iain in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-11-2001, 10:49 AM

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