Like Tree25Likes

is my programming flawless? i need to reach that level of skill

This is a discussion on is my programming flawless? i need to reach that level of skill within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> #include<conio.h> #include<stdlib.h> #include<time.h> using namespace std; class Bowler{//******************************class bowler*********************** int overs,povers,maidovers,runsgiv,wictaken; public: void disp() { cout<<"\n\t BOWLER\n"; cout<<"\novers ...

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

    is my programming flawless? i need to reach that level of skill

    Code:
    #include<iostream>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    using namespace std;
    class Bowler{//******************************class bowler***********************
        int overs,povers,maidovers,runsgiv,wictaken;
        public:
            void disp()
            {
                cout<<"\n\t   BOWLER\n";
                cout<<"\novers played       : "<<povers;
                cout<<"\nmaiden overs       : "<<maidovers;
                cout<<"\nruns given         : "<<runsgiv;
                cout<<"\nwickets taken      : "<<wictaken;
            }
            int giv(char *choose)
            {
                if(choose=="overs")
                {
                    return(overs);
                }
                else if(choose=="maidovers")
                {
                    return(maidovers);
                }
                else if(choose=="runsgiv")
                {
                    return(runsgiv);
                }
                else if(choose=="wictaken")
                {
                    return(wictaken);
                }
            }
            void over()
            {
                cout<<"enter number of overs : ";
                cin>>overs;
            }
            void update(int run,int iout,int j,int balls[])
            {
                int l=0,m;
                if(j==5)
                {
                    povers++;
                    for(m=0;m<6;m++)
                    {
                        if(balls[m]==0)
                            l++;
                    }
                }
                if(l==6)
                {
                    maidovers++;
                    for(m=0;m<6;m++)
                    {
                        balls[m]=1;
                    }
                }
                if(run!=5)
                    runsgiv=run;
                else
                    runsgiv=0;
                if(!iout)
                {
                    wictaken++;
                }
            }
    }ball;
    
    class Batsman{//********************class Batsman*******************************
        int runs,iout,run,mod;
        char name[10],*mout;
        static int count;
        public:
            Batsman()
            {
                iout=1;
            }
            void updatecount()
            {
                count++;
            }
            int giv(char *choose)
            {
                if(choose=="iout")
                {
                    return(iout);
                }
                else if(choose=="runs")
                {
                    return(runs);
                }
                else if(choose=="run")
                {
                    return(run);
                }
            }
            void init(int &a)
            {
                system("cls");
                if(a!=0)
                {
                    cout<<"the batsman #"<<count-1<<" is out now out\n";
                }
                cout<<"enter name of batsman #"<<count<<" : ";
                cin>>name;
                iout++;
                runs=0;
            }
            void disp()
            {
                cout<<"\n\t   BATSMAN #"<<count<<"\n";
                cout<<"\nName               : "<<name;
                cout<<"\nruns made          : "<<runs;
                cout<<"\nstatus             : ";
                switch(mod)
                {
                    case 0:mout="Catch out";break;
                    case 1:mout="Run-out";break;
                    case 2:mout="Wicket";break;
                    case 3:mout="Bold";break;
                    case 4:mout="Hit-Wicket";break;
                }
                if(!iout)
                {
                    cout<<"Out\n";
                    cout<<"mode by which out  : "<<mout;
                }
                else if(iout)
                {
                    cout<<"Not out";
                }
            }
            void update()
            {
                srand(time(NULL));
                run=rand()%7;
                if(run==5)
                {
                    iout--;
                    mod=rand()%5;
                }
                else
                {
                    runs+=run;
                }
            }
    }bats[10];
    
    int Batsman :: count=1;
    
    int main()
    {
        ball.over();
        system("cls");
        char *ch;
        int ov,i=0,balls[6],j,l=0,z=1,k;
        bats[i].init(i);
        cout<<"the score board is ready to be used\n";
        getch();
        system("cls");
        ov=(ball.giv("overs"));
        for(k=0;k<ov;k++)
        {
            if(l)
            {
                break;
            }
            for(j=0;j<6;j++)
            {
                balls[j]=bats[i].giv("run");
                bats[i].update();
                ball.update(bats[i].giv("run"),bats[i].giv("iout"),j,balls);
                if(k+1==1)
                {
                    ch="st";
                }
                else if(k+1==2)
                {    
                    ch="nd";
                }
                else if(k+1==3)
                {
                    ch="rd";
                }
                else
                {
                    ch="th";
                }
                if(j==6)
                {
                    system("cls");
                    cout<<"the "<<k+1<<ch<<" over is finished";
                    cout<<"\n";
                }
                bats[i].disp();
                ball.disp();
                cout<<"\n\nnow the bowler throws the ball...\n";
                cout<<"press enter to update the score board...";
                getch();
                system("cls");
                if(!bats[i].giv("iout"))
                {
                    if(i<10)
                    {
                        i++;
                    }
                    else if (i>10)
                    {
                        l++;
                        j=7;
                        break;
                    }
                    bats[i].updatecount();
                    bats[i].init(i);
                }
            }//end of loop of balls
        }//end of loop of overs
        system("cls");
        if(k==ov)
        {
            cout<<"overs finished";
        }
        else if(l)
        {
            cout<<"all batsmen out !";
        }    
        cout<<"\nend result :-";
        bats[i].disp();
        ball.disp();
    getch();
    return 0;
    }//end of main()

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,756
    Why are you using global variables? You have one function, main() create the instances in this function.

    Code:
    class Batsman{//********************class Batsman*******************************
    ...
    }bats[10];  // Why are you using this global variable?
    Why all the system calls?

    Why are you using the standard C include files instead of the standard C++ include files?

    Do you know you can't use comparison to compare C-strings? Why are you using C-strings in the first place, std::string would probably be a better choice for a C++ program.

    In main() where do you allocate memory for the following pointer?
    Code:
    char *ch;
    Also srand() should only be called once, usually early in main().



    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    1)global variables removed
    2)how am i supposed to pause and clear screen without calling system
    3)as per my bookish knowledge says i know these files and how to use them
    4)so can i use the function strcpy() from string.h header file?
    5)i did a blunder.....i changed that to array of 3
    Code:
    #include<iostream>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<string.h>
    using namespace std;
    class Bowler{//******************************class bowler***********************
        int overs,povers,maidovers,runsgiv,wictaken;
        public:
            void disp()
            {
                cout<<"\n\t   BOWLER\n";
                cout<<"\novers played       : "<<povers;
                cout<<"\nmaiden overs       : "<<maidovers;
                cout<<"\nruns given         : "<<runsgiv;
                cout<<"\nwickets taken      : "<<wictaken;
            }
            int giv(char *choose)
            {
                if(choose=="overs")
                {
                    return(overs);
                }
                else if(choose=="maidovers")
                {
                    return(maidovers);
                }
                else if(choose=="runsgiv")
                {
                    return(runsgiv);
                }
                else if(choose=="wictaken")
                {
                    return(wictaken);
                }
            }
            void over()
            {
                cout<<"enter number of overs : ";
                cin>>overs;
            }
            void update(int run,int iout,int j,int balls[])
            {
                int l=0,m;
                if(j==5)
                {
                    povers++;
                    for(m=0;m<6;m++)
                    {
                        if(balls[m]==0)
                            l++;
                    }
                }
                if(l==6)
                {
                    maidovers++;
                    for(m=0;m<6;m++)
                    {
                        balls[m]=1;
                    }
                }
                if(run!=5)
                    runsgiv=run;
                else
                    runsgiv=0;
                if(!iout)
                {
                    wictaken++;
                }
            }
    };
    
    class Batsman{//********************class Batsman*******************************
        int runs,iout,run,mod;
        char name[10],*mout;
        static int count;
        public:
            Batsman()
            {
                iout=1;
            }
            void updatecount()
            {
                count++;
            }
            int giv(char *choose)
            {
                if(choose=="iout")
                {
                    return(iout);
                }
                else if(choose=="runs")
                {
                    return(runs);
                }
                else if(choose=="run")
                {
                    return(run);
                }
            }
            void init(int &a)
            {
                system("cls");
                if(a!=0)
                {
                    cout<<"the batsman #"<<count-1<<" is out now out\n";
                }
                cout<<"enter name of batsman #"<<count<<" : ";
                cin>>name;
                iout++;
                runs=0;
            }
            void disp()
            {
                cout<<"\n\t   BATSMAN #"<<count<<"\n";
                cout<<"\nName               : "<<name;
                cout<<"\nruns made          : "<<runs;
                cout<<"\nstatus             : ";
                switch(mod)
                {
                    case 0:strcpy(mout,"Catch-out");;break;
                    case 1:strcpy(mout,"Run-Out");break;
                    case 2:strcpy(mout,"Wicket");break;
                    case 3:strcpy(mout,"Bold");break;
                    case 4:strcpy(mout,"Hit-Wicket");break;
                }
                if(!iout)
                {
                    cout<<"Out\n";
                    cout<<"mode by which out  : "<<mout;
                }
                else if(iout)
                {
                    cout<<"Not out";
                }
            }
            void update()
            {
                srand(time(NULL));
                run=rand()%7;
                if(run==5)
                {
                    iout--;
                    mod=rand()%5;
                }
                else
                {
                    runs+=run;
                }
            }
    };
    
    int Batsman :: count=1;
    
    int main()
    {
        Bowler ball;
        Batsman bats[10];
        ball.over();
        system("cls");
        char place[3];
        int ov,i=0,balls[6],j,l=0,z=1,k;
        bats[i].init(i);
        cout<<"the score board is ready to be used\n";
        getch();
        system("cls");
        ov=(ball.giv("overs"));
        for(k=0;k<ov;k++)
        {
            if(l)
            {
                break;
            }
            for(j=0;j<6;j++)
            {
                balls[j]=bats[i].giv("run");
                bats[i].update();
                ball.update(bats[i].giv("run"),bats[i].giv("iout"),j,balls);
                if(k+1==1)
                {
                    strcpy(place,"st");
                }
                else if(k+1==2)
                {    
                    strcpy(place,"nd");
                }
                else if(k+1==3)
                {
                    strcpy(place,"rd");
                }
                else
                {
                    strcpy(place,"th");;
                }
                if(j==6)
                {
                    system("cls");
                    cout<<"the "<<k+1<<place<<" over is finished";
                    cout<<"\n";
                }
                bats[i].disp();
                ball.disp();
                cout<<"\n\nnow the bowler throws the ball...\n";
                cout<<"press enter to update the score board...";
                getch();
                system("cls");
                if(!bats[i].giv("iout"))
                {
                    if(i<10)
                    {
                        i++;
                    }
                    else if (i>10)
                    {
                        l++;
                        j=7;
                        break;
                    }
                    bats[i].updatecount();
                    bats[i].init(i);
                }
            }//end of loop of balls
        }//end of loop of overs
        system("cls");
        if(k==ov)
        {
            cout<<"overs finished";
        }
        else if(l)
        {
            cout<<"all batsmen out !";
        }    
        cout<<"\nend result :-";
        bats[i].disp();
        ball.disp();
    getch();
    return 0;
    }//end of main()
    Last edited by Mukul Kumar; 05-14-2013 at 10:06 AM.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    1.Use the C++ string library.
    string - C++ Reference
    2.Name the variables more meaningfully.
    3.Remove unnecessary comments and put them where you actually need one. (like explanations of what each of the members are doing and why).
    4. choose=="iout"
    You can't compare character arrays/pointers like that. Refer to #1.
    5. Since you know a bit of OOP, structure the code in a different way.
    Make a class to manage the game. This is what you are doing manually here.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,749
    I think there is a design problem in that you wrote two classes, but they do not really model what they are named after. Your Bowler and Batsman classes should not have member functions that perform interactive I/O. Maybe you would overload operator<< to perform output to a std::ostream, and maybe you would overload operator>> to perform input from a std::istream that may well be a file, but that's about it. Interactive I/O would be done in the main function or some other helper function, using the class' interface to manipulate the object.

    Use descriptive names. What is "giv"? What is "ov"? Avoid magic numbers by using named constants.
    King Mir likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

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

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,756
    2)how am i supposed to pause and clear screen without calling system
    To pause the screen you should use something like cin.get(). Unless you want to use a external library you really shouldn't be trying to clear the screen in a console program.

    3)as per my bookish knowledge says i know these files and how to use them
    This answer doesn't make sense. If you know how to use the C++ standard headers, why are you using the C standard headers instead? The following is a C standard header <stdlib.h> the C++ standard header would be <cstdlib> notice the lack of the extension and the leading 'c'.

    4)so can i use the function strcpy() from string.h header file?
    Yes, you use strcpy to copy the strings.

    You still didn't answer this question.
    Do you know you can't use comparison to compare C-strings?
    Jim

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @laser light actually thats a question of chapter classes and objects and i did till the question asked to do

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    replaced all string comparison by strcmp() function

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    Code:
    #include<iostream>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<string.h>
    using namespace std;
    class Bowler{//******************************class bowler***********************
        int overs,povers,maidovers,runsgiv,wictaken;
        public:
            void disp()
            {
                cout<<"\n\t   BOWLER\n";
                cout<<"\novers played       : "<<povers;
                cout<<"\nmaiden overs       : "<<maidovers;
                cout<<"\nruns given         : "<<runsgiv;
                cout<<"\nwickets taken      : "<<wictaken;
            }
            int giv(char *choose)
            {
                if(!strcmp(choose,"overs"))
                {
                    return(overs);
                }
                else if(!strcmp(choose,"maidovers"))
                {
                    return(maidovers);
                }
                else if(!strcmp(choose,"runsgiv"))
                {
                    return(runsgiv);
                }
                else if(!strcmp(choose,"wictaken"))
                {
                    return(wictaken);
                }
            }
            void over()
            {
                cout<<"enter number of overs : ";
                cin>>overs;
            }
            void update(int run,int iout,int j,int balls[])
            {
                int l=0,m;
                if(j==5)
                {
                    povers++;
                    for(m=0;m<6;m++)
                    {
                        if(balls[m]==0)
                            l++;
                    }
                }
                if(l==6)
                {
                    maidovers++;
                    for(m=0;m<6;m++)
                    {
                        balls[m]=1;
                    }
                }
                if(run!=5)
                    runsgiv=run;
                else
                    runsgiv=0;
                if(!iout)
                {
                    wictaken++;
                }
            }
    };
    
    class Batsman{//********************class Batsman*******************************
        int runs,iout,run,mod;
        char name[10],*mout;
        static int count;
        public:
            Batsman()
            {
                iout=1;
            }
            void updatecount()
            {
                count++;
            }
            int giv(char *choose)
            {
                if(!strcmp(choose,"iout"))
                {
                    return(iout);
                }
                else if(!strcmp(choose,"runs"))
                {
                    return(runs);
                }
                else if(!strcmp(choose,"run"))
                {
                    return(run);
                }
            }
            void init(int &a)
            {
                system("cls");
                if(a!=0)
                {
                    cout<<"the batsman #"<<count-1<<" is out now out\n";
                }
                cout<<"enter name of batsman #"<<count<<" : ";
                cin>>name;
                iout++;
                runs=0;
            }
            void disp()
            {
                cout<<"\n\t   BATSMAN #"<<count<<"\n";
                cout<<"\nName               : "<<name;
                cout<<"\nruns made          : "<<runs;
                cout<<"\nstatus             : ";
                switch(mod)
                {
                    case 0:strcpy(mout,"Catch-out");;break;
                    case 1:strcpy(mout,"Run-Out");break;
                    case 2:strcpy(mout,"Wicket");break;
                    case 3:strcpy(mout,"Bold");break;
                    case 4:strcpy(mout,"Hit-Wicket");break;
                }
                if(!iout)
                {
                    cout<<"Out\n";
                    cout<<"mode by which out  : "<<mout;
                }
                else if(iout)
                {
                    cout<<"Not out";
                }
            }
            void update()
            {
                srand(time(NULL));
                run=rand()%7;
                if(run==5)
                {
                    iout--;
                    mod=rand()%5;
                }
                else
                {
                    runs+=run;
                }
            }
    };
    
    int Batsman :: count=1;
    
    int main()
    {
        Bowler ball;
        Batsman bats[10];
        ball.over();
        system("cls");
        char place[3];
        int ov,i=0,balls[6],j,l=0,z=1,k;
        bats[i].init(i);
        cout<<"the score board is ready to be used\n";
        getch();
        system("cls");
        ov=(ball.giv("overs"));
        for(k=0;k<ov;k++)
        {
            if(l)
            {
                break;
            }
            for(j=0;j<6;j++)
            {
                balls[j]=bats[i].giv("run");
                bats[i].update();
                ball.update(bats[i].giv("run"),bats[i].giv("iout"),j,balls);
                if(k+1==1)
                {
                    strcpy(place,"st");
                }
                else if(k+1==2)
                {    
                    strcpy(place,"nd");
                }
                else if(k+1==3)
                {
                    strcpy(place,"rd");
                }
                else
                {
                    strcpy(place,"th");;
                }
                if(j==6)
                {
                    system("cls");
                    cout<<"the "<<k+1<<place<<" over is finished";
                    cout<<"\n";
                }
                bats[i].disp();
                ball.disp();
                cout<<"\n\nnow the bowler throws the ball...\n";
                cout<<"press enter to update the score board...";
                getch();
                system("cls");
                if(!bats[i].giv("iout"))
                {
                    if(i<10)
                    {
                        i++;
                    }
                    else if (i>10)
                    {
                        l++;
                        j=7;
                        break;
                    }
                    bats[i].updatecount();
                    bats[i].init(i);
                }
            }//end of loop of balls
        }//end of loop of overs
        system("cls");
        if(k==ov)
        {
            cout<<"overs finished";
        }
        else if(l)
        {
            cout<<"all batsmen out !";
        }    
        cout<<"\nend result :-";
        bats[i].disp();
        ball.disp();
    getch();
    return 0;
    }//end of main()

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,749
    Quote Originally Posted by Mukul Kumar
    actually thats a question of chapter classes and objects and i did till the question asked to do
    The question probably asked you to create those two classes. What I am saying is that the design of those two classes is flawed. You should be clear on what do the classes model and hence what interface to provide to work with an object of such a class.

    Part of this means that you should resist the temptation to put interactive I/O in your member functions. By doing so, you tightly couple your classes to a console based I/O.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

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

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    2,756
    I don't recommend you use the following, because in my opinion you'll probably forget sometime in the future that this function returns one of three values, zero, greater than zero, or less than zero.
    Code:
    ]if(!strcmp(choose,"runsgiv")
    I recommend:

    Code:
    if(strcmp(choose, "runsgiv") != 0)
    Jim

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,621
    You realize flawless programming implies absolutely no mistakes and no bugs whatsoever - ever. You certainly aren't going to reach that, nor is anyone else. Plus, you are making it harder on yourself by insisting on using C constructs instead of C++ constructs. Well done. You are on your way becoming an awful C++ programmer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @elysia one day i'll show you that nothing is impossible
    Plus don't tell me that what i am ....tell me what should i do!!!
    Last edited by Mukul Kumar; 05-14-2013 at 11:21 AM.

  14. #14
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    Code:
    #include<iostream>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<string.h>
    using namespace std;
    class Bowler{//******************************class bowler***********************
        int overs,povers,maidovers,runsgiv,wictaken;
        public:
            void disp()
            {
                cout<<"\n\t   BOWLER\n";
                cout<<"\novers played       : "<<povers;
                cout<<"\nmaiden overs       : "<<maidovers;
                cout<<"\nruns given         : "<<runsgiv;
                cout<<"\nwickets taken      : "<<wictaken;
            }
            int giv(char *choose)
            {
                if(!strcmp(choose,"overs")==0)
                {
                    return(overs);
                }
                else if(!strcmp(choose,"maidovers")==0)
                {
                    return(maidovers);
                }
                else if(!strcmp(choose,"runsgiv")==0)
                {
                    return(runsgiv);
                }
                else if(!strcmp(choose,"wictaken")==0)
                {
                    return(wictaken);
                }
            }
            void over()
            {
                cout<<"enter number of overs : ";
                cin>>overs;
            }
            void update(int run,int iout,int j,int balls[])
            {
                int l=0,m;
                if(j==5)
                {
                    povers++;
                    for(m=0;m<6;m++)
                    {
                        if(balls[m]==0)
                            l++;
                    }
                }
                if(l==6)
                {
                    maidovers++;
                    for(m=0;m<6;m++)
                    {
                        balls[m]=1;
                    }
                }
                if(run!=5)
                    runsgiv=run;
                else
                    runsgiv=0;
                if(!iout)
                {
                    wictaken++;
                }
            }
    };
    
    class Batsman{//********************class Batsman*******************************
        int runs,iout,run,mod;
        char name[10],*mout;
        static int count;
        public:
            Batsman()
            {
                iout=1;
            }
            void updatecount()
            {
                count++;
            }
            int giv(char *choose)
            {
                if(strcmp(choose,"iout")==0)
                {
                    return(iout);
                }
                else if(strcmp(choose,"runs")==0)
                {
                    return(runs);
                }
                else if(strcmp(choose,"run")==0)
                {
                    return(run);
                }
            }
            void init(int &a)
            {
                system("cls");
                if(a!=0)
                {
                    cout<<"the batsman #"<<count-1<<" is out now out\n";
                }
                cout<<"enter name of batsman #"<<count<<" : ";
                cin>>name;
                iout++;
                runs=0;
            }
            void disp()
            {
                cout<<"\n\t   BATSMAN #"<<count<<"\n";
                cout<<"\nName               : "<<name;
                cout<<"\nruns made          : "<<runs;
                cout<<"\nstatus             : ";
                switch(mod)
                {
                    case 0:strcpy(mout,"Catch-out");;break;
                    case 1:strcpy(mout,"Run-Out");break;
                    case 2:strcpy(mout,"Wicket");break;
                    case 3:strcpy(mout,"Bold");break;
                    case 4:strcpy(mout,"Hit-Wicket");break;
                }
                if(!iout)
                {
                    cout<<"Out\n";
                    cout<<"mode by which out  : "<<mout;
                }
                else if(iout)
                {
                    cout<<"Not out";
                }
            }
            void update()
            {
                srand(time(NULL));
                run=rand()%7;
                if(run==5)
                {
                    iout--;
                    mod=rand()%5;
                }
                else
                {
                    runs+=run;
                }
            }
    };
    
    int Batsman :: count=1;
    
    int main()
    {
        Bowler ball;
        Batsman bats[10];
        ball.over();
        system("cls");
        char place[3];
        int ov,i=0,balls[6],j,l=0,z=1,k;
        bats[i].init(i);
        cout<<"the score board is ready to be used\n";
        getch();
        system("cls");
        ov=(ball.giv("overs"));
        for(k=0;k<ov;k++)
        {
            if(l)
            {
                break;
            }
            for(j=0;j<6;j++)
            {
                balls[j]=bats[i].giv("run");
                bats[i].update();
                ball.update(bats[i].giv("run"),bats[i].giv("iout"),j,balls);
                if(k+1==1)
                {
                    strcpy(place,"st");
                }
                else if(k+1==2)
                {    
                    strcpy(place,"nd");
                }
                else if(k+1==3)
                {
                    strcpy(place,"rd");
                }
                else
                {
                    strcpy(place,"th");;
                }
                if(j==6)
                {
                    system("cls");
                    cout<<"the "<<k+1<<place<<" over is finished";
                    cout<<"\n";
                }
                bats[i].disp();
                ball.disp();
                cout<<"\n\nnow the bowler throws the ball...\n";
                cout<<"press enter to update the score board...";
                getch();
                system("cls");
                if(!bats[i].giv("iout"))
                {
                    if(i<10)
                    {
                        i++;
                    }
                    else if (i>10)
                    {
                        l++;
                        j=7;
                        break;
                    }
                    bats[i].updatecount();
                    bats[i].init(i);
                }
            }//end of loop of balls
        }//end of loop of overs
        system("cls");
        if(k==ov)
        {
            cout<<"overs finished";
        }
        else if(l)
        {
            cout<<"all batsmen out !";
        }    
        cout<<"\nend result :-";
        bats[i].disp();
        ball.disp();
    getch();
    return 0;
    }//end of main()

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,749
    So... are you going to change your program to use std::string?

    EDIT:
    This is wrong:
    Code:
    !strcmp(choose,"overs")==0
    You should get rid of the !

    Or... you could use std::string.
    Elysia and Salem like this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

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

Page 1 of 5 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. game development & programming skill required
    By newprog82 in forum Game Programming
    Replies: 2
    Last Post: 11-02-2010, 11:29 AM
  2. API Programming in network level
    By rchiu5hk in forum C++ Programming
    Replies: 0
    Last Post: 09-07-2009, 10:42 PM
  3. low level programming book
    By CChakra in forum C Programming
    Replies: 5
    Last Post: 09-08-2008, 01:23 PM
  4. Ways to better programming skill
    By Unferth in forum C++ Programming
    Replies: 9
    Last Post: 09-23-2003, 05:35 PM
  5. Low level programming question
    By phooey in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2003, 07:59 AM

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