i already done the scores for each round, i dont know how to calculate the scores for all round, can u help me to solve this?

#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;


//Global variable
const string cardfile=("cards.txt");


//Function Prototypes
void readCards();
int RandomCardP1 (int);
int RandomCardP2 (int);
int CheckType (int [], int ,int);
int CheckSystem (int [], int ,int );
void ShowCardP1(int , string [], string [], string [], string[] , string []);
void ShowCardP2(int, string [], string [], string [], string [], string []);
int Score(int ,int ,int [],int []);
int FinalScore (int,int);


int main(){

    //score
    int sctype[SIZE]={ 3,2,1,2,3,4,1,2,2,2 };
    int scsystem[SIZE]={ 6,4,2,1,5,7,1,2,3,5 };


    //loop for game
    do{
    int scP1=0,scP2=0; 

    for (int round=1;round<6;round++)
    {//loop for 5 round

        cout <<"\t***********";
        cout<<endl<<"\t  ROUND "<<round<<"\n";
        cout <<"\t***********";
        cout<<endl;


    //announce winner and score for each round
    Score(IDcardP1,IDcardP2,sctype-1,scsystem-1);
    cout<<endl;

    cin.get();
    cout<<endl<<endl;


    }//end loop for round


    //score total round
    FinalScore(scP1,scP2);


   } while(respond=='Y'||respond=='y');//end loop for game



}//end main


//scores for each round
int Score(int IDcardP1,int IDcardP2,int sctype[],int scsystem[]){

    int scP1=0, scP2=0;
    cout << "The winner for this round is " <<endl<<endl;
    if (sctype[IDcardP1]>sctype[IDcardP2])
    {
        cout << "  PLAYER 1  " <<endl;
        scP1+=10;
        cout<<endl;
    }
    else
    {
        if (scsystem[IDcardP1]>scsystem[IDcardP2])
        {
            cout << "  PLAYER 1  " <<endl;
            scP1+=10;
            cout<<endl;
        }
        else
        {
            cout << "  PLAYER 2  " <<endl;
            scP2+=10;
        }
        cout<<endl;
    }

    //display score for each round
    cout << "The scores for this round"<<endl;
    cout<<"####################################"<<endl;
    cout<<" Player 1 score :"<<scP1<<endl;
    cout<<" Player 2 score :"<<scP2<<endl;
    cout<<"####################################"<<endl;

}

//score for all round
int FinalScore(int scP1,int scP2){

    //score total round
    cout << "+++++++++++++++++++++++++++++++++"<<endl;
    cout << " Your scores for 5 round : "<< endl;
    cout << " Player 1's score: " << scP1<<endl;
    cout << " Player 2's score: " << scP2<<endl;
    cout << "+++++++++++++++++++++++++++++++++"<<endl;
    cout <<endl;

    //announce the winner for this game
    if (scP1>scP2)
        cout << "\tPLAYER 1 WON!" << endl << endl;
    else
        cout << "\tPLAYER 2 WON!" << endl << endl;
    cout<<endl;
}

There are two approaches you can take: you can either make scP1 and scP2 globals by moving their declarations to the top level outside of the main() function or - preferably - pass them as references to Score() so that they could be updated.

Note that similar issues exist for the readCards() function; you need some way to return the values read in from the file to the main() function. This is where that damnable requirement for parallel arrays (as opposed to packing all values into an single vector<> of a data structure as any sane coder would do) becomes a serious headache - with the parallel arrays, not only do you need to synchronize them manually, but you have to pass each of them individually to each function that uses them. The fact that it uses primitive arrays rather than vector<>s doesn't help, either. Parallel arrays is simply a very bad design for this sort of data structure, and I frankly would complain to the instructor that the textbook is teaching poor techniques.

Anyway, here is what I recommend (warning, not tested):

int Score(int&, int&, int ,int ,int [],int []);

//scores for each round
int Score(int& scP1, int& scP2, int IDcardP1,int IDcardP2,int sctype[],int scsystem[]){
    cout << "The winner for this round is " <<endl<<endl;
    if (sctype[IDcardP1]>sctype[IDcardP2])
    {
        cout << "  PLAYER 1  " <<endl;
        scP1+=10;
        cout<<endl;
    }
    else
    {
        if (scsystem[IDcardP1]>scsystem[IDcardP2])
        {
            cout << "  PLAYER 1  " <<endl;
            scP1+=10;
            cout<<endl;
        }
        else
        {
            cout << "  PLAYER 2  " <<endl;
            scP2+=10;
        }
        cout<<endl;
    }

    //display score for each round
    cout << "The scores for this round"<<endl;
    cout<<"####################################"<<endl;
    cout<<" Player 1 score :"<<scP1<<endl;
    cout<<" Player 2 score :"<<scP2<<endl;
    cout<<"####################################"<<endl;
}

Similarly, move the declarations for CARDS, ID[], cardName[], etc. to the main() function, or else to the top-level global namespace. Again, despite the clumsiness of it, I recommend having them local to main() and passing them by reference to readCards().

void readCards(const int, int&[], string&[], string&[], string&[], string&[], string&[]);

// in main():
    const int CARDS = 10;
    int ID[CARDS];
    string cardName[CARDS] ;
    string pcode[CARDS];
    string type[CARDS];
    string plusMode[CARDS];
    string system[CARDS] ;
// ...
}

void readCards(const int CARDS, int& ID[], string& cardName[], string& pcode[], string& type[], string& plusMode[], string& system[])
    int i=0;

    ifstream infile;
    infile.open("cards.txt");
    if (infile)
    {
        while (!infile.eof()){
        //Read from file
            infile >> ID[i] >> cardName[i] >> pcode[i] >> type[i] >> plusMode[i]>>system[i];
            i++;
        }
        infile.close();
    }
    else
    {
        cout << "File cannot be found.\n";
        exit(0);
    }
}

You may need to make some adjustments to this code, but it should get you started at least.

commented: i already done with the function scores, but for the function finalscore i still didnt get the total score based on function scores +0

The reason you need to change Score() rather than FinalScore() is because Score() is where you are updating the totals.

i already change the Score(), it still updating the scores for the winner each round, so i just want to make each round only get 10 marks for the winner, and when the game is dome, it will appear the total marks for 5 round

Screenshot_(162).png

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.