Like Tree5Likes

error again!!!

This is a discussion on error again!!! within the C++ Programming forums, part of the General Programming Boards category; i divided my code into three files file 1 : the tournament Code: /* difficulty level */ #include"player.h" #include<iostream> #include<conio.h> ...

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

    error again!!!

    i divided my code into three files
    file 1 : the tournament
    Code:
    /* difficulty level */
    #include"player.h"
    #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();
    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;
            case 5:e.settoucman(e);break;
        }
        e.status();
    }//end of function win()
    void delay(int a)
    {
        for(int i=0;i<3*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<<"(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<<"(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<<"light weapons\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<<"medium weapons\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\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<<"light armour\n";
                cout<<"(1) tattered pants \t(cost : 5   armour : 10)\n";
                cout<<"(2) thick cloth       \t(cost : 10  armour : 15)\n";
                cout<<"(3) wooden barrel  \t(cost : 15  armour : 25)\n";
                cout<<"(4) cast iron pads \t(cost : 25  armour : 30)\n";
                cout<<"(5) SS chest       \t(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\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\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':p.shop();break;
            case '3':p.options();break;
            case '4':quit(b);break;
        }
        if(b)
        i++;
        }//end of for
        return 0;
    }//end of main()
    file 2 : player.h
    Code:
    #include<iostream>
    #include<conio.h>
    #include<time.h>
    #include<stdlib.h>
    using namespace std;
    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=15;
                a.arm=2;
                a.dam[0]=2;
                a.dam[1]=5;
                a.mon=15;
                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=20;
                a.arm=8;
                a.dam[0]=8;
                a.dam[1]=12;
                a.mon=30;
                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=30;
                a.arm=15;
                a.dam[0]=10;
                a.dam[1]=15;
                a.mon=50;
                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";
            }
            void settoucman(enemy &a)
            {
                a.health=45;
                a.arm=25;
                a.dam[0]=10;
                a.dam[1]=20;
                a.mon=80;
                a.name="uncommon 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=0;
            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-------*/
    file 3 : drinkp()
    Code:
    #include"player.h"
    #include<iostream>
    #include<conio.h>
    #include<time.h>
    #include<stdlib.h>
    #include<string.h>
    using namespace std;
    void delay(int);
    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
    and i am getting the following error
    D:\All files\large C++ programs\drinkp().o drinkp().cpp.bss+0x0): multiple definition of `p'
    D:\All files\large C++ programs\the tournament.o the tournament.cpp.bss+0x0): first defined here
    D:\All files\large C++ programs\collect2.exe [Error] ld returned 1 exit status
    26 D:\All files\large C++ programs\Makefile.win recipe for target 'TDT.exe' failed
    i need help!!!

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    and those smiles are ': ('

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    First you have several global variables that have single letter names. The use of global variables, much less single lettered named global variables is an extremely bad practice. Get rid of all the global variables, and pass the proper variables to and from your functions. Another extremely bad practice is the use of goto, forget you ever heard of this loop type and learn to use the other more acceptable loop constructs like while, do/while and for.

    Using the using "using namespace std;" statement in your header file is another no-no. Learn to properly scope things in the header file using the scope resolution operator::.

    Next you really could use another header file that contains all the function prototypes. And your header files should contain include guards to prevent including the header more than once.

    I would also recommend you place all your class implementation functions in their own file, like you have already done with your drinkp() function.

    You could also use another file to place all the other functions, except main().

    Jim
    stahta01 and Salem like this.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,683
    Try adding header guards in the .h file.

    Include guard - Wikipedia, the free encyclopedia

    FAQ > Multiple source files for one program (C++ example) - Cprogramming.com

    Edit: Read Jim's post; I did add a second link to an FAQ.

    Tim S.
    Last edited by stahta01; 04-23-2013 at 10:23 AM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    Another quick note you really need to consider your variable and function naming convention inadequate. Too many names that don't mean anything in content of the code. Use meaningful variable names!

    Next in your last post errors are eating me!!! you were told about several problems, your delay() function for example, you need to fix those issues.

    And why did you create a new topic for an existing problem. Changing topics mid-stream looses the content of the old post that is still relevant, in my opinion, in this post.

    Jim

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @jim tell me how am i supposed to exchange the delay function with something else?

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    how am i supposed to exchange the delay function with something else?
    From you previous post:
    Anything is better than that! Even an OS specific method like Sleep, sleep or usleep.
    Jim

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    Code:
    #ifndef DATA_H   
    #define DATA_H   //put just the descriptive part of the class in here  
    class MyClass  
    {  public:    
    //using default default constructor    
    //using default copy constructor    
    //using default assignment operator    
    //using default destructor    
    int getData();    
    void setData(int);   
    private:    
    int data;  
    };  
    #endif
    what is this
    the first two lines of the above code
    and last line of the code?
    Last edited by Mukul Kumar; 04-23-2013 at 11:26 AM.

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i used sleep function but the compiler says that its undefined function!!!

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    Then maybe your operating system doesn't support sleep(), did you try: C++ sleep()?

    what is this
    the first two lines of the above code
    and last line of the code?
    Did you read the links provided for the include guards? They seem to explain those lines to me.

    Jim

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

    oh god!!! its getting far too complex and difficult that i thought!!! :(

    but i will overcome this situation
    please i din't understood the use of #ifndef ,#define and #endif
    and my mind has got confused !!! [~_~]

  12. #12
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    please explain me these errors:-
    D:\All files\large C++ programs\drinkp().o drinkp().cpp: (.bss+0x0): multiple definition of `p'
    D:\All files\large C++ programs\the tournament.o the tournament.cpp: (.bss+0x0): first defined here
    D:\All files\large C++ programs\collect2.exe [Error] ld returned 1 exit status
    D:\All files\large C++ programs\Makefile.win recipe for target 'TDT.exe' failed //TDT.exe is my project-name

  13. #13
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    now i will reply after 18-20 hrs later its mid-night here so good-night

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    What exactly didn't you understand?

    In the C and C++ programming languages, an #include guard, sometimes called a macro guard,
    Do you understand what a macro is? If not here is a definition from this link: C macro

    A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro.
    Jim

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    D:\All files\large C++ programs\drinkp().o drinkp().cpp: (.bss+0x0): multiple definition of `p'
    This message seems fairly well explained to me. You have two definitions of the variable/function named p.

    D:\All files\large C++ programs\the tournament.o the tournament.cpp: (.bss+0x0): first defined here
    This message tells you where it was first defined, the previous message tells you where the second occurrence was.

    Jim

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  2. Replies: 15
    Last Post: 11-28-2011, 10:48 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 1
    Last Post: 11-15-2010, 10:14 AM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM

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