i'm just scratching my head at this issue because i can't seem to figure out what could possibly be causing the error
#include <iostream>
#include "Player.h"
using namespace std;
Player :: Player(int games, string nam) {
name = nam;
array = new int[games];
}
Player :: ~Player() {
delete[] array;
}
int Player :: getNumber(Player g, int index) {
return g.array[index];
}
void Player :: getInputs(Player g, int games) {
for(int i = 0; i < games; i++){
//int location = i + 1;
cout << "Please enter a number at index " << i + 1 << " for player " << g.name << ":";
cin >> g.array[i];
validInput(cin, g, i);
cout << "what's going on" << endl;
}
cout << "Player " << g.name << " selected the following numbers: ";
for(int i = 0; i < games; i++){
cout << g.getNumber(g, i) << " ";
}
}
void Player :: whoWinner(Player g, Player h, int games) {
int player1Score = 0;
int player2Score = 0;
for(int i = 0; i < games; i++) {
if(g.array[i] > h.array[i]){
player1Score++;
}else if(g.array[i] < h.array[i]) {
player2Score++;
}else {
continue;
}
}
if(player1Score > player2Score){
cout << g.name << " Won" << endl;
}else if(player1Score < player2Score){
cout << h.name << "Won" << endl;
}else if (player1Score == player2Score) {
cout << "It's a draw" << endl;
}
}
void Player :: validInput(istream &stream, Player b, int index) {
while(cin.fail()){
cout << "Enter a number" << endl;
cin.clear();
cin.ignore();
cin >> b.array[index];
}
}
the error occurs when the input for the player reaches the last index in the for loop, where it breaks immediately. I don't think i'm freeing any memory at this point so i'm not sure what the issue is
also it breaks before the destructor is reached in the main function if that helps