how to solve no 2 problem? i dont know how to do that, someone please help me :(

Screenshot_(146).png

i already tried but not finish yet
Screenshot_(147).png

Screenshot_(148).png

#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 readData(string,int);
int RandomCardP1 (int);
int RandomCardP2 (int);
int CheckSystem (int , int , int , int );
int ShowCardP1(int , int );
int ShowCardP2(int , int );
int FinalScore();


int main(){

    //to randomize the card
    srand(unsigned(time(0)));

    //declare 
    string nameP1,nameP2;
    char respond='Y';
    int scP1=0,scP2=0;

    //parallel arrays for card
    const int SIZE=10;
    int ID [SIZE]={1,2,3,4,5,6,7,8,9,10}; //Card ID
    string cardName[SIZE]={"Abyss Devolos","Ace Dragon","Anubion A2","Balar B4","Crystal Dranzer","Cyclone Belfyre","Dark-X Nepstrius","Diomedes D2","Doomscizor","Vatryek Wing Accel"};//Card name
    string p_code[SIZE]={"F0647", "E7609", "E1057", "E4726", "F0217", "F3965", "E4749", "E1062", "E1033", "B9492 "};//Product code
    string type[SIZE]={"Balance", "Attack", "Defense", "Attack", "Balance", "Stamina", "Defense", "Attack", "Attack", "Attack"};//Type
    string plusMode [SIZE]={"NA", "NA", "NA", "NA", "NA", "Attack", "NA", "NA", "NA", "NA"};
    string system [SIZE]={"SpeedStorm", "HyperSphere", "Dual-Layer", "SlingShock", "Burst", "QuadDrive", "SlingShock", "Dual-Layer", "SwitchStrike", "Burst" };



    cout<<"\n\tWELCOME TO ELECTRONIC BEYBLADE TRADING CARD GAME"<<endl;
    cout<<"================================================================";
    cout<<endl<<endl;


    cout<<"Player 1 enter you name : ";
    getline(cin,nameP1);
    cout<<"Player 2 enter your name : ";
    getline(cin,nameP2);    
    cout<<endl;


    cout<<"\t\t\tGAME START"<<endl;
    cin.get();

    do{

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

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

    int Ran;
    int IDcardP1,IDcardP2, cardP1, cardP2, typeP1,typeP2,systemP1,systemP2;

    cout << "Player 1 press enter to pick a card ";
    cin.get();
    IDcardP1 = RandomCardP1 (Ran);
    cout << "Player 1 card is : " << IDcardP1 <<endl<<endl;

    cout << "Player 2 press enter to pick a card ";
    cin.get();
    IDcardP2 = RandomCardP2 (Ran);
    while (IDcardP2==IDcardP1)
    {
        IDcardP2 = RandomCardP2 (Ran);  
    }
    cout <<"Player 2 card is : " << IDcardP2 << endl;
    cin.get();

    cout<<"--------------------------------"<<endl;
    cout << " \t####SHOW CARD#### "<<endl;

    cout << "Player 1 card :"<<endl;
    cout << ShowCardP1(cardP1,SIZE) <<endl;
    cout << "Player 2 card :"<<endl;
    cout << IDcardP2 <<endl;

    cin.get();
    cout<<"Your winner for this round is "<<endl;
    CheckSystem;

    cin.get();
    cout<<endl;

    }

    //display total score
    cout<<"----------------------------------"<<endl;
    cout<<" Player 1 score :"<<" "<<endl;
    cout<<" Player 2 score :"<<" "<<endl;
    cout<<"----------------------------------"<<endl;
    cout<<endl;

    if (scP1>scP2){
        cout<<"The winner is Player 1 " <<endl;
    }
    else
        cout<<"The winner is Player 2 " <<endl;


    cout<<"\t\t\tGAME OVER"<<endl;
    cout<<"******************************************************************"<<endl;
    cout<<"Do you want to continue this game?(Y/N): ";
    cin>>respond;
    cout<<endl; 
   } while(respond!='N');

    cout<<"Thankyou, see you again!";
    return 0; 
}

//card infromation
void readData(string Data){

    ifstream infile;
    infile.open("cards.txt");
    string line;

    if (!infile.is_open())
        cout << "Failure to open the file";

    while (getline(infile, line))
    {
        cout << line << '\n';
    }

    infile.close();

}


//Generate a random card number
int RandomCardP1 (int Ran)
{
    unsigned int IDcardP1 = 0;
    IDcardP1 = rand()%9 + 1;

    return IDcardP1;
}

int RandomCardP2 (int Ran)
{
    unsigned int IDcardP2= 0;
    IDcardP2 = rand()%9 + 1;

    return IDcardP2;
}

//check system precedence
int CheckSystem (int systemP1, int systemP2, int scP1, int scP2)
{
    if (systemP1>systemP2)
        {
            cout << "Player 1" <<endl;
            scP1+=10;
        }
        else
        {
            cout << "Player 2" <<endl;
            scP2+=10;
        }
    return scP1,scP2;
}





//check type and system precedence
int CheckType(int typeP1,int typeP2, int scP1, int scP2)
{
    if (typeP1>typeP2)
    {
        cout << "Player 1" <<endl;
        scP1 +=10;
    }
    else
    {
        cout << "Player 2" <<endl;
        scP2 +=10;
    }


}




//detail card and score in each round
void ShowCardP1(int cardP1,int typeP1, int systemP1){

    if (cardP1 == 1) {
            cout<< " Product code : F0647  " ;
            cout<< "    Abyss Devolos      ";
            cout<< "    Type : Balance     ";
            cout<< "    PlusMode : NA      ";
            cout<< "  System : SpeedStorm  ";
            typeP1= 3;
            systemP1= 6;
        }
        else 
            if(cardP1 == 2) {
                cout<<" Product code : E7609  ";
                cout<<"      Ace Dragon       ";
                cout<<"    Type : Attack      ";
                cout<<"    PlusMode : NA      ";
                cout<<"  System : HyperSphere ";
                typeP1= 2;
                systemP1= 4;
            }
        else 
            if (cardP1 == 3) {
                cout<<" Product code : E1057  ";
                cout<<"      Anubion A2       ";
                cout<<"    Type : Defense     ";
                cout<<"    PlusMode : NA      ";
                cout<<"  System : Dual-Layer  ";
                typeP1= 1;
                systemP1= 2;
            }
        else
            if (cardP1 == 4) {
                cout<<" Product code : E4726  ";
                cout<<"        Balar B4       ";
                cout<<"    Type : Attack      ";
                cout<<"    PlusMode : NA      ";
                cout<<"  System : SlingShock  ";
                typeP1= 2;
                systemP1= 1;
            }
        else
            if (cardP1 == 5) {
                cout<<" Product code : F0217  ";
                cout<<"    Crystal Dranzer    ";
                cout<<"    Type : Balance     ";
                cout<<"    PlusMode : NA      ";
                cout<<"    System : Burst     ";
                typeP1= 3;
                systemP1= 5;
            }
        else
            if (cardP1 == 6) {
                cout<<" Product code : F3965  ";
                cout<<"   Cyclone Belfyre     ";
                cout<<"    Type : Stamina     ";
                cout<<"  PlusMode : Attack    ";
                cout<<"  System : Quadrive    ";
                typeP1= 4;
                systemP1= 7;
            }
        else
            if (cardP1 == 7) {
                cout<<" Product code : E4749  ";
                cout<<"   Dark-X Nepstrius    ";
                cout<<"    Type : Defense     ";
                cout<<"    PlusMode : NA      ";
                cout<<"  System : SlingShock  ";
                typeP1= 1;
                systemP1= 1;
            }
        else
            if (cardP1 == 8) {
                cout<<" Product code : F1062  ";
                cout<<"      Diomedes D2      ";
                cout<<"     Type : Attack     ";
                cout<<"    PlusMode : NA      ";
                cout<<"  System : Dual-Layer  ";
                typeP1= 4;
                systemP1= 2;
            }
        else
            if (cardP1 == 9) {
                cout<<" Product code : E1033  ";
                cout<<"      Doomscizor       ";
                cout<<"    Type : Attack      ";
                cout<<"    PlusMode : NA      ";
                cout<<" System : SwitchStrike ";
                typeP1= 1;
                systemP1= 3;
            }
        else
            if  (cardP1 == 10){
                cout<<" Product code : B9492  ";
                cout<<"  Vatryek Wing Accel   ";
                cout<<"    Type : Attack      ";
                cout<<"    PlusMode : NA      ";
                cout<<"    System : Burst     ";
                typeP1= 1;
                systemP1= 5;
            }


    //cout<< cardP1;




}

int ShowCardP2(int cardID, int scP2){



}

//score for all round
int FinalScore(){




}

If I might recommend a bit of an improvement:

void ShowCardP1(int cardP1, string cardName[], string p_code[], string type[], string plusMode, string system[]) {
    cout<< "Product code: " << p_code[cardP1] << "  " << endl;
    cout<< cardName[cardP1] << "  " << endl ;
    cout<< "Type: " << type[cardP1] << "  " << endl;
    cout<< "PlusMode:" << plusMode[cardP1] << endl;
    cout<< "System: " << system[cardP1] << endl;
}

Mind you, if it weren't for the (rather absurd) instructions to use parallel arrays, I would instead declare a struct type to hold this information:

struct CardDetails {
    string name, code, type, mode, system;
} cards[SIZE] = {{"Abyss Devolos", "F0647", "Balance", "NA", "SpeedStorm"},
                 {"Ace Dragon", "E7609", "Attack", "NA", "HyperSphere"},
                 // ... etc. 
                };

// ...

void ShowCardP1(int cardP1, string cards[]) {
    cout<< "Product code: " << cards.code[cardP1] << endl;
    cout<< cards.name[cardP1] << endl ;
    cout<< "Type: " << cards.type[cardP1] << endl;
    cout<< "PlusMode:" << cards.mode[cardP1] << endl;
    cout<< "System: " << cards.system[cardP1] << endl;
}

This is probably a bit ahead of where your course is right now, however.

commented: aaaa thankyouuu sooo muschhhh +0

the number of card is not same with the card detail, what should i do to make sure the number of card same with card detail?

Screenshot_(150).png

this is my new coding c++

#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 readData(string,int);
int RandomCardP1 (int);
int RandomCardP2 (int);
int CheckSystem (int , int , int , int );
void ShowCardP1(int , string [], string [], string [], string[] , string []);
void ShowCardP2(int, string [], string [], string [], string [], string []);
int FinalScore();


int main(){

    //to randomize the card
    srand(unsigned(time(0)));

    //declare 
    string nameP1,nameP2;
    char respond='Y';
    int scP1=0,scP2=0;

    //parallel arrays for card
    const int SIZE=10;
    int ID [SIZE]={1,2,3,4,5,6,7,8,9,10}; //Card ID
    string cardName[SIZE]={"Abyss Devolos","Ace Dragon","Anubion A2","Balar B4","Crystal Dranzer","Cyclone Belfyre","Dark-X Nepstrius","Diomedes D2","Doomscizor","Vatryek Wing Accel"};//Card name
    string p_code[SIZE]={"F0647", "E7609", "E1057", "E4726", "F0217", "F3965", "E4749", "E1062", "E1033", "B9492 "};//Product code
    string type[SIZE]={"Balance", "Attack", "Defense", "Attack", "Balance", "Stamina", "Defense", "Attack", "Attack", "Attack"};//Type
    string plusMode [SIZE]={"NA", "NA", "NA", "NA", "NA", "Attack", "NA", "NA", "NA", "NA"};
    string system [SIZE]={"SpeedStorm", "HyperSphere", "Dual-Layer", "SlingShock", "Burst", "QuadDrive", "SlingShock", "Dual-Layer", "SwitchStrike", "Burst" };



    cout<<"\n\tWELCOME TO ELECTRONIC BEYBLADE TRADING CARD GAME"<<endl;
    cout<<"================================================================";
    cout<<endl<<endl;


    cout<<"Player 1 enter you name : ";
    getline(cin,nameP1);
    cout<<"Player 2 enter your name : ";
    getline(cin,nameP2);    
    cout<<endl;


    cout<<"\t\t\tGAME START"<<endl;
    cin.get();

    do{

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

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

    int Ran;
    int IDcardP1,IDcardP2, typeP1,typeP2,systemP1,systemP2;

    cout << "Player 1 press enter to pick a card ";
    cin.get();
    IDcardP1 = RandomCardP1 (Ran);
    cout << "Player 1 card is : " << IDcardP1 <<endl<<endl;

    cout << "Player 2 press enter to pick a card ";
    cin.get();
    IDcardP2 = RandomCardP2 (Ran);
    while (IDcardP2==IDcardP1)
    {
        IDcardP2 = RandomCardP2 (Ran);  
    }
    cout <<"Player 2 card is : " << IDcardP2 << endl;
    cin.get();

    cout<<"--------------------------------"<<endl;
    cout << " \t####SHOW CARD#### "<<endl;

    cout << "Player 1 card :"<<endl;
    ShowCardP1(IDcardP1,cardName, p_code, type, plusMode, system);
    cout<<endl;
    cout << "Player 2 card :"<<endl;
    ShowCardP2(IDcardP2,cardName, p_code, type, plusMode, system);
    cout<<endl;
    cout<<"--------------------------------"<<endl;

    cin.get();
    cout<<"Your winner for this round is "<<endl;
    CheckSystem;

    cin.get();
    cout<<endl;

    }

    //display total score
    cout<<"----------------------------------"<<endl;
    cout<<" Player 1 score :"<<" "<<endl;
    cout<<" Player 2 score :"<<" "<<endl;
    cout<<"----------------------------------"<<endl;
    cout<<endl;

    if (scP1>scP2){
        cout<<"The winner is Player 1 " <<endl;
    }
    else
        cout<<"The winner is Player 2 " <<endl;


    cout<<"\t\t\tGAME OVER"<<endl;
    cout<<"******************************************************************"<<endl;
    cout<<"Do you want to continue this game?(Y/N): ";
    cin>>respond;
    cout<<endl; 
   } while(respond!='N');

    cout<<"Thankyou, see you again!";
    return 0; 
}

//card information
void readData(string Data){

    ifstream infile;
    infile.open("cards.txt");
    string line;

    if (!infile.is_open())
        cout << "Failure to open the file";

    while (getline(infile, line))
    {
        cout << line << '\n';
    }

    infile.close();

}


//Generate a random card number
int RandomCardP1 (int Ran)
{
    unsigned int IDcardP1 = 0;
    IDcardP1 = rand()%9 + 1;

    return IDcardP1;
}

int RandomCardP2 (int Ran)
{
    unsigned int IDcardP2= 0;
    IDcardP2 = rand()%9 + 1;

    return IDcardP2;
}

//check system precedence
int CheckSystem (int systemP1, int systemP2, int scP1, int scP2)
{
    if (systemP1>systemP2)
        {
            cout << "Player 1" <<endl;
            scP1+=10;
        }
        else
        {
            cout << "Player 2" <<endl;
            scP2+=10;
        }
    return scP1,scP2;
}





//check type and system precedence
int CheckType(int typeP1,int typeP2, int scP1, int scP2)
{
    if (typeP1>typeP2)
    {
        cout << "Player 1" <<endl;
        scP1 +=10;
    }
    else
    {
        cout << "Player 2" <<endl;
        scP2 +=10;
    }


}




//detail card and score in each round
void ShowCardP1(int IDcardP1, string cardName[], string p_code[], string type[], string plusMode[], string system[]) {
    cout<< "Product code: " << p_code[IDcardP1] << "  " << endl;
    cout<< cardName[IDcardP1] << "  " << endl ;
    cout<< "Type: " << type[IDcardP1] << "  " << endl;
    cout<< "PlusMode:" << plusMode[IDcardP1] << endl;
    cout<< "System: " << system[IDcardP1] << endl;
}


void ShowCardP2(int IDcardP2, string cardName[], string p_code[], string type[], string plusMode[], string system[]) {
    cout<< "Product code: " << p_code[IDcardP2] << "  " << endl;
    cout<< cardName[IDcardP2] << "  " << endl ;
    cout<< "Type: " << type[IDcardP2] << "  " << endl;
    cout<< "PlusMode:" << plusMode[IDcardP2] << endl;
    cout<< "System: " << system[IDcardP2] << endl;
}


//score for all round
int FinalScore(){




}
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.