Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help understand what I am doing wrong in this Yahtzee c++ program???

ID: 669342 • Letter: C

Question

Can someone help understand what I am doing wrong in this Yahtzee c++ program???

#include "stdafx.h"

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>

#include <utility>
#include <set>
#include <numeric>
#include <time.h>

using namespace std;

map< pair<int, int>, vector<int> > CategorizationMemo;

int numScore(int Dices[5], int Digit)
{
   int Total = 0;

   for (int i = 0; i<5; i++)
       if (Dices[i] == Digit) Total += Digit;

   return Total;
}

int chance(int Dices[5])
{
   int Total = 0;
   for (int i = 0; i<5; i++) Total += Dices[i];
   return Total;
}

int OfSameKind(int Dice[5], int n, int DiceCount[7])
{

   bool Found = false;
   for (int i = 1; i<7; i++) if (DiceCount[i] >= n) { Found = true; break; }

   if (n == 5 && Found) return 50;

   if (Found) return chance(Dice);

   return 0;
}

int fullHouse(int DicesCount[7])
{
   bool TwoEqual = false, ThreeEqual = false, FiveEqual = false;
   for (int i = 1; i<7;i++)
       if (DicesCount[i] == 2) TwoEqual = true;
       else if (DicesCount[i] == 3) ThreeEqual = true;
       else if (DicesCount[i] == 5) FiveEqual = true;

       if ((TwoEqual && ThreeEqual) || FiveEqual) return 40;
       else return 0;
}

int straight(int DicesCount[7], int n)
{
   int bigSequence = 0, PresentSequence = 0;
   for (int i = 1; i<7; i++)
       if (DicesCount[i] && DicesCount[i + 1])
       PresentSequence++;
       else bigSequence = max(PresentSequence + 1, bigSequence), PresentSequence = 0;

       if (bigSequence == n && n == 5) return 35;
       if (bigSequence >= n && n == 4) return 25;
       return 0;
}

inline int calcScore(int Config[13], int Scores[13][13])
{
   int TotalScore = 0;

   for (int i = 0; i<13; i++)
   {
       TotalScore += Scores[Config[i]][i];
       if (i == 5) TotalScore += TotalScore >= 63 ? 35 : 0;
   }

   return TotalScore;
}
int * SA(int Scores[13][13])
{
   int * Config = new int[13];
   for (int i = 0; i<13; i++)
       Config[i] = i;
   int T = 1000;
   int IS, TotalScore, ValueA, ValueB, A, B;
   srand(time(NULL));
   while (T > 0)
   {
       for (int i = 0; i<100; i++)
       {
           A = rand() % 13;
           B = rand() % 13;
           ValueA = Config[A];
           ValueB = Config[B];
           IS = calcScore(Config, Scores);
           swap(Config[A], Config[B]);
           int TotalScore = calcScore(Config, Scores);
          
           if ((rand() % 100) + 1 > 100 * P)
               swap(Config[A], Config[B]);
       }

       T--;
   }

   return Config;
}
int _tmain(int argc, _TCHAR* argv[])
{
   int Dice[13][5];

   int Score[13][13];
   int counter = 0;
   while (1)
   {

       counter++;
       for (int i = 0; i<13; i++)
           for (int j = 0; j<13; j++)
           Score[i][i] = -1;
       int DiceCount[13][7] = { 0 };
       int Score[13];
       for (int i = 0; i<13; i++)
       {
           for (int j = 0; j < 5; j++)
               if (scanf("%d", &Dice[i][j]) != 1) {
                   return 0;
               }
                  
               else {
                   DiceCount[i][Dice[i][j]]++;
               }
               Score[i] = numScore(Dice[i], 1);
               Score[i] = numScore(Dice[i], 2);
               Score[i] = numScore(Dice[i], 3);
               Score[i] = numScore(Dice[i], 4);
               Score[i] = numScore(Dice[i], 5);
               Score[i] = numScore(Dice[i], 6);
               Score[i] = chance(Dice[i]);

               Score[i] = OfSameKind(Dice[i], 3, DiceCount[i]);
               Score[i] = OfSameKind(Dice[i], 4, DiceCount[i]);
               Score[i] = OfSameKind(Dice[i], 5, DiceCount[i]);

               Score[i]= straight(DiceCount[i], 4);
               Score[i]= straight(DiceCount[i], 5);

               Score[i] = fullHouse(DiceCount[i]);
       }

       int * TotalResult = Score;

       int TotalScore = 0;
       int Bonus = 0;
       for (int i = 0; i<13; i++)
       {
           printf("%d ", Score[TotalResult[i]]);
           TotalScore += Score[TotalResult[i]];
           if (i == 5 && TotalScore >= 63) Bonus = 35;
       }
       TotalScore += Bonus;
       printf("%d %d ", Bonus, TotalScore);

       system("pause");
   }

Explanation / Answer

1) missing a closing '}' at the end of the file.

2) Identifier P is undefined in int *SA(int **) function

please add the comments properly or give a clear description for the problem to better help you solve the problem.