to calculate score for all round

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?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
#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, scP2;
    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;
   
}
Last edited on
Do you know what the return type of a function is? Your Score and FinalScore functions both promise to return ints, but you never return anything.

Presumably you want to return a score from the Score function, and add that to some accumulation variable.

https://cplusplus.com/doc/tutorial/functions/
i already update my coding, when i run, it doesnt work
Please don't update your original post again, it makes the thread not flow in a straight path; just make a new post with updated code.

First thing you should learn about communication in programming is that "it doesnt work" is one of the most useless things you can say for all but the most trivial of issues. If you want people to help you, they need to know what specifically doesn't work -- what is the behavior you are expecting, and how does it differ, precisely, from the behavior you are currently seeing?

Fortunately, the issue here is a common mistake. A function only returns one value. One int, in your case. You can't return two things separated by commas, that's not how that works.

Furthermore, in FinalScore, you are simply returning the input variables. This is wholly redundant, and you could just make this be a void function.

In Score, scP1 and scP2 are not initialized (line 72). Both are local variables. Different variables have different scopes. The variable in one function is completely separate from the variable in another.
https://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm

I would suggest having a sum variable in main.
e.g.
1
2
3
4
5
int sum = 0;

// within loop:

    sum += Score(IDcardP1,IDcardP2,sctype-1,scsystem-1);


Hopefully that gives you some stuff to try out. Post the next iteration of your code in a new post so others can follow along and also help.

If you need a function to update two different variables, one option is to pass the variables as references.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example program
#include <iostream>
#include <string>

void set_scores(int& p1_score, int& p2_score)
{
    p1_score = 15;
    p2_score = 32;
}


int main()
{
  int p1_score_blah; // notice: name doesn't need to match set_scores
  int p2_score;
  set_scores(p1_score_blah, p2_score);
  
  std::cout << p1_score_blah << " " << p2_score << '\n';
}
Last edited on
sory for my mistake, i will make my coding as before, thankyou for help me, i will try my best
L23

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


but called as:
L48

 
Score(IDcardP1,IDcardP2,sctype-1,scsystem-1);


????
Looking at the code, I don't really understand what you're trying to do...

Perhaps you could provide a description as to what the program is supposed to do.
@avocado16, just saying "it doesn't work" is too little information.

It would seem your code is for a card game. Telling us what the game is would go a long way to helping us to be able to help you.

If this is for an class assignment please post the ENTIRE assignment.
Topic archived. No new replies allowed.