Like Tree6Likes
  • 2 Post By jimblumberg
  • 3 Post By jimblumberg
  • 1 Post By iMalc

errors are eating me!!!

This is a discussion on errors are eating me!!! within the C++ Programming forums, part of the General Programming Boards category; i don't know that what is the problem of this code i kept in mind all bad habits and worked ...

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

    errors are eating me!!!

    i don't know that what is the problem of this code i kept in mind all bad habits and worked hard on it
    i was able to compile the code first 10-15 times then the same error is occoring.....

    C:\Users\Mukul\AppData\Local\Temp\ccdetHvX.o: In function `main':
    D:/All files/large C++ programs/the tournament.cpp:1231: undefined reference to `options()'
    collect2.exe: error: ld returned 1 exit status

    Execution terminated

    and my code is
    Code:
    #include<iostream>
    #include<conio.h>
    #include<time.h>
    #include<stdlib.h>
    #include<string.h>
    static bool a=1,b=0;
    using namespace std;
    void delay(int);
    void clear();
    void noem();
    void drinkp();
    void tutorial();
    void options();
    void shop();
    void win(int &a,int &b);
    void quit(int&);
    void weapons();
    void armour();
    void extras();
    void fo();
    void bou();
    void boa();
    class player{
        int health,arm,arm1,dam[2],mon,melee[2],w[3][5],a[3][5],health1,hp,dp,edam,d;
        char name[10],*damd[5],*wpn,*ar,*dd;
        public:
    /*---------start of struct enemy----------*/    
            struct enemy
        {
            int health,arm,dam[2],mon;
            char *name,*damd[4];
            void status()
            {
                system("cls");
                cout<<name<<"'s profile\n";
                cout<<"health : "<<health;
                cout<<"\ndamage : "<<dam[0]<<"-"<<dam[1];
                cout<<"\narmour's strength : "<<arm;
                cout<<"\nprize : "<<mon;
                cout<<"\npress any key to continue...";
                getch();
                system("cls");
            }//end of e.status()
            void settorat(enemy &a)
            {
                a.health=10;
                a.arm=0;
                a.dam[0]=0;
                a.dam[1]=3;
                a.mon=20;
                a.name="RAT";
                a.damd[0]="that rat taunts you...\n";
                a.damd[1]="woo rat just bit your left hand's finger...\n";
                a.damd[2]="aaargh this rat is biting me\n";
                a.damd[3]="oooooaaaaahhh this rat bit your neck\n";
            }
            void settohrat(enemy &a)
            {
                a.health=20;
                a.arm=2;
                a.dam[0]=5;
                a.dam[1]=10;
                a.mon=25;
                a.name="RAT-king";
                a.damd[0]="that rat-king taunts you...\n";
                a.damd[1]="woo rat-king just bit your left hand's finger...\n";
                a.damd[2]="aaargh this rat-king is biting me\n";
                a.damd[3]="oooooaaaaahhh this rat-king bit your neck\n";
            }
            void settofarmer(enemy &a)
            {
                a.health=35;
                a.arm=10;
                a.dam[0]=8;
                a.dam[1]=12;
                a.mon=50;
                a.name="farmer";
                a.damd[0]="that farmer taunts you...\n";
                a.damd[1]="woo farmer just hit your head with a hay-stack...\n";
                a.damd[2]="aaargh he just punches your face\n";
                a.damd[3]="your mouth is full of blood!!!\n";
            }
            void settocman(enemy &a)
            {
                a.health=55;
                a.arm=20;
                a.dam[0]=10;
                a.dam[1]=15;
                a.mon=80;
                a.name="common man";
                a.damd[0]="this man taunts you...\n";
                a.damd[1]="woo this man just hit your head badly...\n";
                a.damd[2]="aaargh he just punches your face\n";
                a.damd[3]="your mouth is full of blood!!!\n";
            }
        }e;//end of struct enemy
    /*------end of struct enemy--------*/
        player()
        {
            health=100;
            health1=health;
            arm=0;
            arm1=0;
            hp=0;
            edam=0;
            dp=0;
            dam[0]=0;
            dam[1]=2;
            mon=20;
            melee[0]=1;
            cout<<"enter your player's name : ";
            cin>>name;
            ar="tattered shirt\n";
            melee[1]=5;
            damd[0]="you hit like a lazy man...\n";
            damd[1]="you did some damage to him\n";
            damd[2]="you sliced through him\n";
            damd[3]="you did some damage\n";
            damd[4]="your weapon sliced through his belly...\n";
            wpn="small twig\n";
            fo();
            switch(d)
            {
                case 0:dd="easy";break;
                case 1:dd="medium";break;
                case 2:dd="hard";break;
                case 3:dd="insane!";break;
            }
        }
        void status()
        {
            system("cls");
            cout<<name<<"'s profile\n";
            cout<<"current mode : "<<dd;
            cout<<"\nhealth : "<<health;
            cout<<"\nweapon damage : "<<dam[0]<<"-"<<dam[1];
            cout<<"\nbonus damage : +"<<edam;
            cout<<"\nmelee damage : "<<melee[0]<<"-"<<melee[1];
            cout<<"\nweapon used : "<<wpn;
            cout<<"armour's strength : "<<arm;
            cout<<"\narmour in use : "<<ar;
            cout<<"money left : "<<mon;
            cout<<"\npress any key to continue...";
            getch();
            system("cls");
        }
        void drinkp();
        void start();
        void armour();
        void weapons();
        void extras();
        void options();
        void win(int &,int &);
        void fo();
        void shop();
        void boa();
        void bou();    
    }p;
    /*------end of class player-------*/
    void player:: drinkp()
        {
            for(int i=0;i!=1;i+=0)
            {
            system("cls");
            char a;
            cout<<"(1) health portions left "<<p.hp<<"\n";
            cout<<"(2) damage portions left "<<p.dp<<"\n";
            cout<<"(3) back\n";
            a=getch();
            switch(a)
            {
                case '1':if(p.hp)
                    {
                        system("cls");
                        cout<<"your health is increased by 30\n";
                        cout<<"health : "<<p.health+30;
                        p.health+=30;
                        p.hp--;
                        delay(3000);
                    }
                    else
                    {
                        system("cls");
                        cout<<"either buy some portions in shop or leave";
                        delay(3000);
                    }break;
                case '2':{if(p.dp)
                    {
                        system("cls");
                        cout<<"your damage is increased by 5\n";
                        p.edam+=5;
                        p.dp--;
                        delay(3000);
                    }//end of if
                    else
                    {
                        system("cls");
                        cout<<"either buy some portions in shop or leave";
                        delay(3000);
                    }
                    }break;
                case '3':i=1;break;
            }//end of switch
        }//end of for
    }//end of function
    void player :: fo()
    {
        for(int aa=0;aa<3;aa++)
        {
                for(int bb=0;bb<5;bb++)
                {
                    p.w[aa][bb]=1;
                    p.a[aa][bb]=1;
                }//end of for(bb)
        }//end of for(aa)
    }//end of function fo()
    
    
    void player:: start()
    {
        srand(time(NULL));
        system("cls");
        cout<<"when you are ready press enter...\n";
        getch();
        p.status();
        char a;
        e.settorat(e);
        int z=0,d,j=1;
        for(int i=0;i!=1;)
        {
            system("cls");
            cout<<"what will you do...\n";
            cout<<"(1) punch him\n";
            cout<<"(2) use your "<<p.wpn;
            cout<<"(3) see your status\n";
            cout<<"(4) see enemy's status\n";
            cout<<"(5) drink portions\n";
            cout<<"(6) leave";
            a=getch();
            switch(a)
            {
            case '1':{
                system("cls");
                z=(rand()%(p.melee[1]-p.melee[0])+(p.melee[0]+1));
                if(e.arm==0&&e.health>0)
                {
                    e.health-=z;
                    if(e.health<0)
                    e.health=0;
                    cout<<p.damd[rand()%4]<<"\ndamage done "<<z;
                    cout<<"\n"<<e.name<<"'s health "<<e.health ;
                }
                else if(e.arm>0)
                {
                    e.arm-=(2)*z;
                    if(e.arm<0)
                    e.arm=0;
                    cout<<p.damd[rand()%4]<<"\ndamage done to armour "<<z;
                    cout<<"\n"<<e.name<<"'s armour "<<e.health ;
                }
                else
                {
                    win(i,++j);
                    continue;
                }
                delay(2000);
            }break;
            case '2':{
                system("cls");
                z=rand()%((p.dam[1])-(p.dam[0]));
                z+=(p.dam[0]+1+p.edam);
                if(e.arm<=0&&e.health>0)
                {
                    e.health-=z;
                    if(e.health<0)
                    e.health=0;
                }
                else if(e.arm>0)
                {
                    e.arm-=2*z;
                    if(e.arm<0)
                    e.arm=0;
                }
                else
                {
                    win(i,++j);
                    continue;
                }
                cout<<p.damd[rand()%4]<<"\ndamage done "<<z;
                cout<<"\n"<<e.name<<"'s health "<<e.health ;
                delay(3000);
            }break;
            case '3':p.status();continue;
            case '4':e.status();continue;
            case '5':drinkp();continue;
            case '6':i=1;break;
            default :continue;
        }//end of switch
        if(i)
        break;
        //enemy;s turn
        if(e.health<=0)
        {
            win(i,++j);
            continue;
        }
        system("cls");
        z=rand()%(e.dam[1]-e.dam[0])+e.dam[0]+1;
        d=(rand()%4);
        cout<<e.damd[d];
        if(p.arm==0&&p.health>0)
        {
            p.health-=z;
            if(p.health<0)
            p.health=0;
            cout<<"your health reduces to "<<p.health;
            cout<<"\n"<<e.name<<" hurts you by : "<<z;
        }
        else if(p.arm>0)
        {
            p.arm-=2*z;
            if(p.arm<0)
            p.arm=0;
            cout<<"damage done to armour "<<2*z;
            cout<<"\narmour left : "<<p.arm;
        }
        delay(3000);
       }//end of loop
    }//end of function start()
    void clear(int &a)
    {
        for(int i=0;i<a;i++)
        {
            cout<<"\b";
        }
    }
    void player :: win(int &a,int &b)
    {
        system("cls");
        a=0;
        cout<<"you defeated "<<e.name<<" and got "<<e.mon<<" money as reward..";
        p.mon+=e.mon;
        getch();
        system("cls");
        cout<<"now you will fight your next opponent...\npress any key to goto shop...";
        shop();
        switch(b)
        {
            case 2:e.settohrat(e);break;
            case 3:e.settofarmer(e);break;
            case 4:e.settocman(e);break;
        }
        p.status();
        e.status();
    }//end of function win()
    void delay(int a)
    {
        for(int i=0;i<2*a;i++)
        {
            cout<<"            "<<"\b\b\b\b\b\b\b\b\b\b\b\b";// this delay function is used to delay the process 
        }
    }
    
    void ab()
    {
        system("cls");
        cout<<"you had purchased this item before\n";
        getch();
    }
    void tutorial()
    {
        int i,k;
        system("cls");
        cout<<"learn how to play this game...\npress any key to continue.";
        getch();
        system("cls");
        char a[68],
             a1[]="you will start as a man who wants to win the 'Tournament of Death'",
             a2[]="when you were heading to the stadiun you accidently fell into",
             a3[]="gutter and met a small rat guarding his king",
             a4[]="now after defeating rat-king after his slave you find a way out ",
             a5[]="in between the fight between common and uncommon man",
             a6[]="now after beating the two men you start your journey to tournament";
        for(k=0;k<6;k++)
        {
            switch(k)
            {
                case 0:strcpy(a,a1);break;
                case 1:strcpy(a,a2);break;
                case 2:strcpy(a,a3);break;
                case 3:strcpy(a,a4);break;
                case 4:strcpy(a,a5);break;
                case 5:strcpy(a,a6);break;
            }
            
            for(i=0;;i++)
            {
                if(a[i]=='\0')
                {
                    getch();
                    break;
                }
                else if(a[i]!='\0')
                {    
                    cout<<a[i];
                    delay(80);
                }
            }
            for(;i>0;i--)
            {
                cout<<"\b";
                delay(20);
            }
        }
    }//end of funtion tutorial()
    void player:: options()
    {
        for(int i=0;i!=1;)
        {
            system("cls");
            cout<<"(1) set difficulty level\n(2) set your player's name\n(3) reset game\n(4) back\n";
            char a;
            a=getch();
            system("cls");
            switch(a)
            {
                case '1':cout<<"(1) easy\n(2) medium\n(3) hard\n(4) insane!\n";
                    a=getch();
                    switch(a)
                    {
                        case '1':p.d=0;break;
                        case '2':p.d=1;break;
                        case '3':p.d=2;break;
                        case '4':p.d=3;break;
                        default :cout<<"no! that is not an option...";
                                getch();
                                continue;
                    }
                    break;
                case '2':cout<<"enter your new name : ";
                        cin>>p.name;
                        break;
                case '3': ::a=1;cout<<"noe start the game again to erase the progress\n";
                        getch();
                        break;
                case '4':i++;break;
                default :continue;
            }//end of switch()
        }//end of for
    }//end of function options()
    void player :: shop()
    {
    
        back:
        int b=1;
        system("cls");
        cout<<"welcome to the shop\n";
        cout<<"(1) to buy weapons\n (2) to buy armour\n (3) to buy extras\n (4) back";
        cout<<"\nmoney left : "<<p.mon<<"\n";
        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;
        }
    }//end of function shop()
    void player:: extras()
    {
        system("cls");
        static int mon=25;
        for(int i=0;i!=1;i+=0)
        {
            system("cls");
            cout<<"choose one of the following.....\n(1) heal yourself\n(2) repair armour\n(3) buy portions\n(4) upgrade health\n(5) back";
            cout<<"\nmoney left : "<<p.mon<<"\n";
            char a=getch();
            switch(a)
            {
                case '1':{
                        system("cls");
                        cout<<"press 'y' to confirm and 'n' to go back and 'f' to use all your money to restore health\n";
                        cout<<"the cost is : "<<(p.health1-p.health)/3;
                        cout<<"\nmoney left : "<<p.mon<<"\n";
                        a=getch();
                        switch(a)
                        {
                            case 'y':if(p.mon>=(p.health1-p.health)/3)
                                {
                                    cout<<"\nyou restored your health back to "<<p.health1;
                                    p.mon-=(p.health1-p.health)/3;
                                    p.health=p.health1;
                                    delay(1500);
                                }
                                else
                                noem();
                            case 'n':continue;
                            case 'f':if(p.mon)
                                {
                                    cout<<"\nyou restored your health up to "<<p.health1;
                                    p.health+=((p.mon/((p.health1-p.health)/3))*(p.health1-p.health));
                                    p.mon=0;
                                    delay(1500);
                                }
                                else if(!p.mon)
                                noem();
                                break;
                        }//end of inner switch
                    }//end of case '1'
                case '2':{
                     system("cls");
                     cout<<"press'y' to confirm and 'n' to go back\n";
                        cout<<"the cost is : "<<(p.arm1-p.arm)/3;
                        cout<<"\nmoney left : "<<p.mon<<"\n";
                        a=getch();
                        switch(a)
                        {
                            case 'y':if(p.mon>=(p.arm1-p.arm)/3)
                                {
                                    cout<<"\nyou restored your armour back to "<<p.arm1;
                                    p.mon-=(p.arm1-p.arm)/3;
                                    p.arm=p.arm1;
                                    delay(1000);
                                }
                                else
                                noem();
                            case 'n':continue;
                        }
                    }//end of case '2'
                case '3':{
                        system("cls");
                        cout<<"which portions will you buy?\n";
                        cout<<"(1) health portion (cost : 10  restoration : 30)\n";
                        cout<<"(2) damage portion (cost : 25  increase in damage : 5)\n";
                        cout<<"(3)back\n";
                        cout<<"money left : "<<p.mon<<"\n";
                        switch((a=getch()))
                        {
                            case '1':{
                                    system("cls");
                                    if(p.mon>=10)
                                    {
                                        p.hp++;
                                        p.mon-=10;
                                        cout<<"you bought a health portion for 10 money\n";
                                        delay(2000);
                                    }
                                    else
                                    noem();
                                }break;
                            case '2':{
                                    system("cls");
                                    if(p.mon>=25)
                                    {
                                        p.dp++;
                                        p.mon-=25;
                                        cout<<"you bought a damage portion for 25 money\n";
                                        delay(2000);
                                    }
                                    else
                                    noem();
                                }break;
                        }//end of switch inside case '3' of outer switch
                    }break;//end of case '3'
                case '4':cout<<"\nmoney needed "<<mon<<"\nconfirm your option(y/n)";
                    a=getch();
                    if(a=='y')
                    {
                        if(p.mon>=mon)
                        {
                            p.health1+=20;
                            p.health=p.health1;
                            p.mon-=mon;
                            mon+=25;
                        }
                        else
                        {
                            cout<<"\nsorry not enough money...\n";
                            delay(1500);
                            continue;
                        }
                    }
                    else if(a=='n')
                    break;
                case '5':i=1;break;
            }//end of switch()
        }//end of for
    }//end of function extras()
    void player:: weapons()
    {
        back:
        int b=1;
        system("cls");
        cout<<"choose...\n(1) light weapons \n(2) medium weapons\n(3) heavy weapons\n(4) back\n";
        cout<<"money left : "<<p.mon<<"\n";
        char a=getch();
        switch(a)
        {
            case '1':{
                system("cls");
                cout<<"\nlight weapons press...\n";
                cout<<"(1) small stick        (cost : 10   damage : 0-3)\n";
                cout<<"(2) huge twig          (cost : 15   damage : 2-5)\n";
                cout<<"(3) sharp bamboo spear (cost : 20   damage : 5-10)\n";
                cout<<"(4) rusty sword        (cost : 30   damage : 10-20)\n";
                cout<<"(5) iron sword           (cost : 40   damage : 15-25) \n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{
                        if(p.mon>=10&&p.w[0][0])
                           {
                        p.dam[0]=0;
                        p.dam[1]=3;
                        p.wpn="small stick\n";
                        bou();
                        p.mon-=10;
                        p.w[0][0]--;
                           }
                           else if(p.mon<10&&p.w[0][0])
                           noem();
                           else if(!p.w[0][0])
                           ab();
    
                    }break;
                    case '2':{
                        if(p.mon>=15&&p.w[0][1])
                           {
                        p.dam[0]=2;
                        p.dam[1]=5;
                        p.wpn="huge twig\n";
                        bou();
                        p.mon-=15;
                        p.w[0][1]--;
                           }
                        else if(!p.w[0][1])
                        ab();
                        else if(p.mon<15&&p.w[0][1])
                        noem();
                    }break;
                    case '3':{
                        if(p.mon>=20&&p.w[0][2])
                           {
                        p.dam[0]=5;
                        p.dam[1]=10;
                        p.wpn="sharp bamboo spear\n";
                        bou();
                        p.mon-=20;
                        p.w[0][2]--;
                        }
                        else if(p.mon<20&&p.w[0][2])
                           noem();
                           else if(!p.w[0][2])
                           ab();
                    }break;
                    case '4':{
                        if(p.mon>=30&&p.w[0][3])
                           {
                        p.dam[0]=10;
                        p.dam[1]=20;
                        p.wpn="rusty sword\n";
                        bou();
                        p.mon-=30;
                        p.w[0][3]--;
                        }
                        else if(p.mon<30&&p.w[0][3])
                           noem();
                           else if(!p.w[0][3])
                           ab();
                    }break;
                    case '5':{    if(p.mon>=40&&p.w[0][4])
                           {
                        p.dam[0]=15;
                        p.dam[1]=25;
                        p.wpn="iron sword\n";
                        bou();
                        p.w[0][4]--;
                        p.mon-=40;
                        }
                        else if(p.mon<40&&p.w[0][4])
                           noem();
                           else if(!p.w[0][4])
                           ab();
                    }break;
                    case '6':system("cls");break;
                }
            }break;
            case '2':
            {
                system("cls");
                cout<<"\n\nmedium weapons press...\n";
                cout<<"(1) medium sword      (cost : 50   damage : 20-30)\n";
                cout<<"(2) long sword          (cost : 60   damage : 20-35)\n";
                cout<<"(3) sharp sword       (cost : 80   damage : 40-60)\n";
                cout<<"(4) cast iron sword   (cost : 100  damage : 50-100)\n";
                cout<<"(5) SS sword          (cost : 120  damage : 60-100)\n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{    if(p.mon>=50&&p.w[1][0])
                           {
                        p.dam[0]=20;
                        p.dam[1]=30;
                        p.w[1][0]--;
                        p.wpn="medium sword\n";
                        bou();
                        p.mon-=50;
                        }
                        else if(p.mon<50&&p.w[1][0])
                           noem();
                           else if(!p.w[1][0])
                           ab();
                    }break;
                    case '2':{    if(p.mon>=60&&p.w[1][1])
                           {
                        p.dam[0]=20;
                        p.dam[1]=35;
                        p.w[1][1]--;
                        p.wpn="long sword\n";
                        bou();
                        p.mon-=60;
                        }
                        else if(p.mon<60&&p.w[1][2])
                           noem();
                           else if(!p.w[1][1])
                           ab();
                    }break;
                    case '3':{    if(p.mon>=80&&p.w[1][2])
                           {
                        p.dam[0]=40;
                        p.dam[1]=60;
                        p.wpn="sharp sword\n";
                        p.w[1][2]--;
                        bou();
                        p.mon-=80;
                        }
                        else if(p.mon<80&&p.w[1][2])
                           noem();
                           else if(!p.w[1][2])
                           ab();
                    }break;
                    case '4':{
                        if(p.mon>=100&&p.w[1][3])
                           {
                        p.dam[0]=50;
                        p.w[1][3]--;
                        p.wpn="cast iron sword\n";
                        bou();
                        p.dam[1]=100;
                        p.mon-=100;
                        }
                        else if(p.mon<100&&p.w[1][3])
                           noem();
                           else if(!p.w[1][3])
                           ab();
    
                    }break;
                    case '5':{
                        if(p.mon>=120&&p.w[1][4])
                           {
                        p.wpn="SS sword\n";
                        p.dam[0]=60;
                        bou();
                        p.dam[1]=100;
                        p.mon-=120;
                        p.w[1][4]--;
                        }
                        else if(p.mon<120&&p.w[1][4])
                           noem();
                           else if(!p.w[1][4])
                           ab();
                    }break;
                    case '6':system("cls");break;
                }
            }break;
            case '3':
            {
                system("cls");
                cout<<"heavy weapons press...\n";
                cout<<"(1) silver sword         (cost : 125   damage : 65-100)\n";
                cout<<"(2) golden sword         (cost : 150   damage : 80-120)\n";
                cout<<"(3) diamond tipped sword (cost : 180   damage : 100-200)\n";
                cout<<"(4) diamond sword        (cost : 200   damage : 150-250)\n";
                cout<<"(5) legenery sword       (cost : 300   damage : 500-600)\n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{
                        if(p.mon>=125&&p.w[2][0])
                           {
                        p.dam[0]=65;
                        p.w[2][0]--;
                        p.dam[1]=100;
                        p.wpn="silver sword\n";
                        bou();
                        p.mon-=125;
                        }
                        else if(p.mon<125&&p.w[2][0])
                           noem();
                           else if(!p.w[2][0])
                           ab();
                    }break;
                    case '2':{
                        if(p.mon>=150&&p.w[2][1])
                           {
                        p.dam[0]=80;
                        p.wpn="golden sword\n";
                        bou();
                        p.dam[1]=120;
                        p.w[2][1]--;
                        p.mon-=150;
                        }
                        else if(p.mon<150&&p.w[2][1])
                           noem();
                           else if(!p.w[2][1])
                           ab();
                    }break;
                    case '3':{
                        if(p.mon>=180&&p.w[2][2])
                           {
                        p.dam[0]=100;
                        p.dam[1]=200;
                        p.wpn="emereld sword\n";
                        bou();
                        p.w[2][2]--;
                        p.mon-=180;
                        }
                        else if(p.mon<180&&p.w[2][2])
                           noem();
                           else if(!p.w[2][2])
                           ab();
                    }break;
                    case '4':{
                            if(p.mon>=200&&p.w[2][3])
                           {p.dam[0]=150;
                        p.dam[1]=250;
                        p.w[2][3]--;
                        p.wpn="diamond sword\n";
                        bou();
                        p.mon-=200;
                        }
                        else if(p.mon<200&&p.w[2][3])
                           noem();
                           else if(!p.w[2][3])
                           ab();
                    }break;
                    case '5':{
                            if(p.mon>=300&&p.w[2][4])
                           {p.dam[0]=500;
                        p.dam[1]=600;
                        p.wpn="legenry sword\n";
                        bou();
                        p.mon-=300;
                        p.w[2][4]--;
                        }
                        else if(p.mon<300&&p.w[2][3])
                           noem();
                           else if(!p.w[2][4])
                           ab();
                    }break;
                    case '6':system("cls");break;
                }
            }break;
            case '4':b=0;break;
        }
        if(b)
        goto back;
    }
    void noem()
    {
        system("cls");
        cout<<"you have not enough money to buy this item...\n";
        delay(1000);
        system("cls");
    }
    void player:: armour()
    {
        back:
        int b=1;
        system("cls");
        char a;
        cout<<"(1) light armour\n(2) medium armour\n(3) heavy armour\n(4) back";
        cout<<"\nmoney left : "<<p.mon<<"\n";
        a=getch();
        switch(a)
        {
            case '1':
            {
                system("cls");
                cout<<"press..\n";
                cout<<"(1) tattered pants (cost : 5   armour : 10)\n";
                cout<<"(2) thick cloth       (cost : 10  armour : 15)\n";
                cout<<"(3) wooden barrel  (cost : 15  armour : 25)\n";
                cout<<"(4) cast iron pads (cost : 25  armour : 30)\n";
                cout<<"(5) SS chest       (cost : 45  armour : 40)\n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{
                            if(p.mon>=5&&p.a[0][0])
                           {p.arm=10;
                        p.arm1=10;
                        p.mon-=5;
                        p.ar="tattered pants\n";
                        boa();
                        p.a[0][0]--;
                        }
                        else if(p.mon<5&&p.a[0][0])
                           noem();
                           else if(!p.a[0][0])
                           ab();
                    }break;
                    case '2':{
                            if(p.mon>=10&&p.a[0][1])
                           {p.arm=15;
                           p.arm1=15;
                        p.ar="thick cloth\n";
                        boa();
                        p.mon-=10;
                        p.a[0][1]--;
                        }
                        else if(p.mon<10&&p.a[0][1])
                           noem();
                           else if(!p.a[0][2])
                           ab();
                    }break;
                    case '3':{
                            if(p.mon>=15&&p.a[0][2])
                           {p.arm=25;
                           p.arm1=25;
                        p.ar="wooden barrel\n";
                        boa();
                        p.mon-=15;
                        p.a[0][2]--;
                        }
                        else if(p.mon<15&&p.a[0][2])
                           noem();
                           else if(!p.a[0][2])
                           ab();
                    }break;
                    case '4':{
                            if(p.mon>=25&&p.a[0][3])
                           {p.arm=30;
                           p.arm1=30;
                        p.ar="cast iron pads\n";
                        boa();
                        p.mon-=25;
                        p.a[0][3]--;
    
                        }
                        else if(p.mon<25&&p.a[0][3])
                           noem();
                           else if(!p.a[0][3])
                           ab();
                    }break;
                    case '5':{
                            if(p.mon>=45&&p.a[0][4])
                           {p.arm=40;
                           p.arm1=40;
                        p.ar="SS chest\n";
                        boa();
                        p.mon-=45;
                        p.a[0][4]--;
    
                        }
                        else if(p.mon<45&&p.a[0][4])
                           noem();
                           else if(!p.a[0][4])
                           ab();
                    }break;
                    case'6':system("cls");break;
                }//end of switch(a) inside switch(a)
            }break;//end of case 1 of switch(a)
            case '2':{
                system("cls");
                cout<<"medium armour   press....\n";
                cout<<"(1) iron armour         (cost : 50   armour : 50)\n";
                cout<<"(2) thick iron armour   (cost : 60   armour : 55)\n";
                cout<<"(3) samurai armour      (cost : 80   armour : 75)\n";
                cout<<"(4) super steel armour  (cost : 100  armour : 80)\n";
                cout<<"(5) wootz steel armour  (cost : 120  armour : 100)\n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{
                        if(p.mon>=50&&p.a[1][0])
                           {p.arm=50;
                           p.arm1=50;
                        p.a[1][0]--;
                        p.ar="iron armour\n";
                        boa();
                        p.mon-=50;
                        }
                           else if(p.mon<50&&p.a[1][0])
                           noem();
                           else if(!p.a[1][0])
                           ab();
                    }break;
                    case '2':{
                        if(p.mon>=60&&p.a[1][1])
                           {p.ar="thick iron armour\n";
                        boa();
                        p.a[1][1]--;
                        p.arm=55;
                        p.arm1=55;
                        p.mon-=60;
                        }
                           else if(p.mon<60&&p.a[1][1])
                           noem();
                           else if(!p.a[1][1])
                           ab();
                    }break;
                    case '3':{
                            if(p.mon>=80&&p.a[1][2])
                           {p.arm=75;
                           p.arm1=75;
                        p.ar="samurai armour\n";
                        boa();
                        p.a[1][2]--;
                        p.mon-=80;
                        }
    
                        else if(p.mon<80&&p.a[1][2])
                           noem();
                           else if(!p.a[1][2])
                           ab();
                    }break;
                    case '4':{
                            if(p.mon>=100&&p.a[1][2])
                           {p.arm= 80;
                        p.ar="super steel armour\n";
                        p.a[1][2]--;
                        boa();
                        p.arm1=80;
                        p.mon-=100;
                        }
    
                        else if(p.mon<100&&p.a[1][2])
                           noem();
                           else if(!p.a[1][3])
                           ab();
                    }break;
                    case '5':{
                            if(p.mon>=120&&p.a[1][2])
                           {p.arm=100;
                        p.ar="wootz steel armour\n";
                        boa();
                        p.a[1][2]--;
                        p.arm1=100;
                        p.mon-=120;
                        }
                        else if(p.mon<120&&p.a[1][2])
                           noem();
                           else if(!p.a[1][4])
                           ab();
                    }break;
                    case '6':system("cls");break;
                }break;//end of switch(a) inside switch(a)
            case '3':{
                system("cls");
                cout<<"heavy armour   press....\n";
                cout<<"(1) silver armour          (cost : 125   armour : 110)\n";
                cout<<"(2) gold armour              (cost : 150   armour : 120)\n";
                cout<<"(3) emereld armour         (cost : 170   armour : 150)\n";
                cout<<"(4) diamond armour            (cost : 200   armour : 175)\n";
                cout<<"(5) armour of turtle king  (cost : 500   armour : 400)\n";
                cout<<"(6) back\n";
                cout<<"money left : "<<p.mon<<"\n";
                a=getch();
                switch(a)
                {
                    case '1':{
                            if(p.mon>=125&&p.a[2][0])
                           {p.arm=110;
                           p.arm1=110;
                        p.ar="silver armour\n";
                        boa();
                        p.a[2][0]--;
                        p.mon-=125;
                        }
    
                        else if(p.mon<125&&p.a[2][0])
                           noem();
                           else if(!p.a[2][0])
                           ab();
                    }break;
                    case '2':{
                            if(p.mon>=150&&p.a[2][1])
                           {p.ar="gold armour\n";
                        p.arm=120;
                        p.arm1=120;
                        boa();
                        p.a[2][1]--;
                        p.mon-=150;
                        }
    
                        else if(p.mon<150&&p.a[2][1])
                           noem();
                           else if(!p.a[2][1])
                           ab();
                    }break;
                    case '3':{
                            if(p.mon>=170&&p.a[2][2])
                           {p.arm=150;
                           p.arm1=150;
                        p.ar="emereld armour\n";
                        boa();
                        p.mon-=170;
                        p.a[2][2]--;
                        }
    
                        else if(p.mon<170&&p.a[2][2])
                           noem();
                           else if(!p.a[2][1])
                           ab();
                    }break;
                    case '4':{
                            if(p.mon>=200&&p.a[2][3])
                           {p.arm=175;
                           p.arm1=175;
                        p.ar="diamond armour\n";
                        boa();
                        p.mon-=200;
                        p.a[2][3]--;
                           }
                           else if(p.mon<200&&p.a[2][3])
                           noem();
                           else if(!p.a[2][3])
                           ab();
                    }break;
                    case '5':{
                            if(p.mon>=500&&p.a[2][4])
                           {p.arm=400;
                           p.arm1=400;
                        p.ar="armour of turtle king\n";
                        boa();
                        p.a[2][4]--;
                        p.mon-=500;
                        }
                        else if(p.mon<500&&p.a[2][4])
                           noem();
                           else if(!p.a[2][4])
                           ab();
                    }break;
                    case '6':system("cls");break;
                }
            }break;
            case '4':b=0;break;
        }}
        if(b)
        goto back;
    }
    void player :: bou()
    {
        system("cls");
        cout<<"you bought this weapon named : "<<p.wpn;
        cout<<"and having damage : "<<p.dam[0]<<"-"<<p.dam[1];
        delay(3000);
        system("cls");
    }
    void player :: boa()
    {
        system("cls");
        cout<<"you bought this armour named : "<<p.ar;
        cout<<"and having strength : "<<p.arm;
        delay(3000);
        system("cls");
    }
    
    void quit(bool &b)
    {
        system("cls");
        char a;
        cout<<"are you sure want to quit?(y/n)";
        a=getch();
        switch(a)
        {
            case 'y':
            case 'Y':{
                    system("cls");
                    cout<<"thanks for playing this game ";
                    for(int i=0;i<5;i++)
                    {
                        cout<<(char)1<<" "<<(char)2;
                        delay(500);
                        cout<<"\b\b\b"<<(char)2<<" "<<(char)1;
                        delay(500);
                        cout<<"\b\b\b";
                    }
                    b++;
                }
            case 'n':
            case 'N':break;
            default :cout<<"\nchoose one of the two (y/n)\n";
                    quit(b);
        }//end of switch(a) inside function quit()
        cout<<"\n";
        system("pause");
    }//end of function quit()
    
    int main()
    {
        for(int i=0;i!=1;)
        {
        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();
        cout<<"\n";
        switch(a)
        {
            case '1':p.start();break;
            case '2':tutorial();break;
            case '3':options();break;
            case '4':quit(b);break;
        }
        if(b)
        i++;
        }//end of for
        return 0;
    }//end of main()

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    well i guess its too long...but i will wait

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,684
    Where do you implement the function options()? I see a function void player::options() but no void options() function.

    Also you may want to consider breaking your program up into several files. For example a header and implementation file for your class would be a good start.


    Jim

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    oh k so i'll change that to p.options(); in main()

    Quote Originally Posted by jimblumberg View Post
    Also you may want to consider breaking your program up into several files. For example a header and implementation file for your class would be a good start.
    Jim
    and i din't understood anything of this
    i am not an advanced programmer but i do it for fun
    my knowledge is not too much about C++ (which i will gain in coming time)
    i know v.basics like the loops the break,continue and goto keywords
    if - else if
    switch
    function(uses and application + inlining)
    classes and structure(upto bascis till constructors)
    and thats all but i'll be learning a lot by the end of this year

    and thanks a lot the code has run successfully jim

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    2,684
    First forget you ever heard of a goto statement. Learn to use the other proper loops, like do/while(), do{}, and for{} loops.

    Next you may want to study the following link: Programs with multiple files and try to break your one large file into several smaller easier to maintain files.


    Jim
    stahta01, Elysia and iMalc like this.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Code:
    void delay(int a)
    {
        for(int i=0;i<2*a;i++)
        {
            cout<<"            "<<"\b\b\b\b\b\b\b\b\b\b\b\b";// this delay function is used to delay the process
        }
    }
    Cringe cringe CRINGE!!!

    Anything is better than that! Even an OS specific method like Sleep, sleep or usleep.
    Salem likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strdup function is eating a letter
    By DeanWinchester in forum C Programming
    Replies: 15
    Last Post: 05-31-2012, 08:06 AM
  2. Tree traversal eating/creating elements?
    By patricio2626 in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2006, 06:37 AM
  3. How eating effects your sleep
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-28-2005, 12:32 PM
  4. Memory Eating - Dangerous?
    By Machewy in forum C++ Programming
    Replies: 23
    Last Post: 12-31-2003, 02:28 AM
  5. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM

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