This is supposed to be the game NIM. As far as I know the actual gameplay is sound, it just won't compile. I have attached both my program and the errors I'm getting. Any help would be greatly appreciated!
Errors:
subtraction.cpp: In function ‘void print_rods(int*, int)’:
subtraction.cpp:157: error: ‘percentage’ was not declared in this scope
subtraction.cpp: In function ‘void smallest(int*, int)’:
subtraction.cpp:216: error: invalid type argument of ‘unary *’
subtraction.cpp:216: error: invalid type argument of ‘unary *’
subtraction.cpp: In function ‘void largest(int, int)’:
subtraction.cpp:235: error: ‘array’ cannot be used as a function
subtraction.cpp:235: error: ‘array’ cannot be used as a function
subtraction.cpp:241: error: invalid types ‘int[int]’ for array subscript
subtraction.cpp: In function ‘void average(int*, int)’:
subtraction.cpp:250: error: ‘sum’ cannot be used as a function
subtraction.cpp: In function ‘void move(int*, int, int, int, int)’:
subtraction.cpp:293: error: ‘remove’ cannot be used as a function
subtraction.cpp: In function ‘int remove_read(int*, int)’:
subtraction.cpp:348: error: ‘rod_chosesn’ was not declared in this scope
subtraction.cpp:349: error: ‘remove’ was not declared in this scope
Program:
#include <iostream>
#include <iomanip>
using namespace std;
// FUNCTION PROTOTYPES GO HERE:
int num_rods( const int NUM_RODS_MAX);
void rod_size( int array[], const int array_size, const int NUM_OBJ_MAX);
void how_many( int array[], const int NUM_OBJ_MAX, int i);
void print_rods( int array[], const int array_size);
void print_pound( int array[]);
int sum_objects( int array[], const int array_size);
void percent( const int sum, int array[], int i);
void stats( int array[], int array_size);
void smallest( int array[], int array_size);
void largest( int array[], int array_size);
void average( int array[], int array_size);
bool rod_empty( int array[], int array_size);
void move( int array[], int array_size, int player, int rod_chosen, int remove);
int pick_rod( int player);
void validate_rod_num( int player, int rod_chosen, int array_size);
void validate_rod_obj( int array[], int player, int rod_chosen);
void remove_from_rod( int array[], int rod_chosen);
int remove_read( int array[], int rod_chosen);
void modify( int array[], int rod_chosen, int remove);
void winner( int player);
void player_switch( int& player);
int main()
{
// Define variables and constants here
const int NUM_RODS_MAX = 15; //maximum number of rods allowed
const int NUM_OBJ_MAX = 10; //maximum number of objects per rod allowed
int array_size = 0; //size of the array
int array[array_size];
int player = 1; //which player is playing
bool empty = false; //are all the rods empty
int rod_chosen; //rod being played
int remove; //number of objects being removed
if (rod_empty( array, array_size))
{
winner( player);
}
else{
print_rods( array, array_size);
stats( array, array_size);
player_switch( player);
}
}
return 0;
}
// FUNCTION DEFINITIONS GO HERE:
int num_rods( const int MAX_NUM_RODS)
{
int rods = 0; //number of rods in the game
cout<< "How many rods are in this game? ";
cin>> rods;
while (rods < 1 || rods > MAX_NUM_RODS)
{
cout<< "Number of rods must be positive and less than or equal to 15" << endl;
cout<< "Enter number of rods again: ";
cin>> rods;
}
return (rods);
}
void rod_size( int array[], const int array_size, const int NUM_OBJ_MAX)
{
int i; //used to count in the loop
for (i = 0; i < array_size; i++)
{
how_many( array, NUM_OBJ_MAX, i);
}
}
void how_many( int array[], const int NUM_OBJ_MAX, int i)
{
cout<< "How many objects on rod " << i << ": ";
cin>> array[i];
while (array[i] < 1 || array[i] > NUM_OBJ_MAX)
{
cout<< "Sorry, the number of objects must be positive and less than or equal to 10." << endl;
cout<< "Hpw many objects are on rod " << i << ": ";
cin>> array[i];
}
}
void print_rods( int array[], const int array_size)
{
cout<< endl;
int i; //used to count in the loop
int sum = sum_objects( array, array_size); //sum of all the objects
for (i = 0; i < array_size; i++)
{
cout<< setw(7) << "Rod " << i << ":";
cout<< setw(15) << print_pound;
percentage( sum, array, i);
}
cout<< endl;
}
int sum_objects( int array[], const int array_size)
{
int i; //used to count in loop
int sum = 0; //sum of all the objects
for (i = 0; i < array_size; i++)
{
sum = sum + array[i];
}
return (sum);
}
void print_pound( int array[])
{
int i; //used to count in loop
for (i = 0; i <= array[i]; i++)
{
cout<< "#";
}
}
void percentage( const int sum, int array[], int i)
{
int percent;
void stats( int array[], int array_size)
{
smallest( array, array_size);
largest( array, array_size);
average( array, array_size);
}
void smallest( int *array, int array_size)
{
int small = 0; //smallest rod
int i; //used to count in the loop
for (i = 0; i < array_size; i++)
{
if (*array[i] < *array[small])
{
small = i;
}
}
cout<< "Rod " << small << " has the smallest number of objects with " << array[small] << " object(s)." << endl;
}
void largest( int array, int array_size)
{
int large = 0; //largest rod
int i; //used to count in the loop
for (i = 0; i < array_size; i++)
{
if (array(i) > array(large))
{
large = i;
}
}
cout<< "Rod " << large << " has the largest number of objects with " << array[large] << " object(s)." << endl;
}
void average( int array[], int array_size)
{
int sum = sum( array, array_size); //total number of objects
int num_rods = 0; //number of rods that have one or more object
int i; //used to count in the loop
double avg; //average number of objects
for ( i = 0; i < array_size; i++)
{
if ( array[i] > 0)
{
num_rods++;
}
}
avg = sum / num_rods;
cout<< "The average number of objects per rod (i.e., rods with objects) is " << fixed << setprecision(2) << avg << " objects." << endl;
}
bool rod_empty( int array[], int array_size)
{
int i; //used to count in the loop
for (i = 0; i < array_size; i++)
{
if (array[i] > 0)
{
return (false);
}
}
return (true);
}
void move( int array[], int array_size, int player, int rod_chosen, int remove)
{
rod_chosen = pick_rod( player);
validate_rod_num( player, rod_chosen, array_size);
validate_rod_obj( array, player, rod_chosen);
remove( array, rod_chosen);
}
int pick_rod( int player)
{
int rod_chosen; //rod the player choses to play
cout<< "Player (" << player << ") : Which rod would you like to play? ";
cin>> rod_chosen;
return (rod_chosen);
}
void validate_rod_num( int player, int rod_chosen, int array_size)
{
while (rod_chosen < 0 || rod_chosen >= array_size)
{
cout<< "Invalid rod number. Please try again." << endl;
pick_rod( player);
}
}
void validate_num_obj( int array[], int player, int rod_chosen)
{
while (array[rod_chosen] < 1)
{
cout<< "Rod " << rod_chosen << " has zero objects. Please select a different rod." << endl;
pick_rod( player);
}
}
void remove_from_rod( int array[], int rod_chosen)
{
int remove; //number of objects to remove from the rod
remove = remove_read( array, rod_chosen);
while (remove > array[rod_chosen])
{
cout<< "Can only remove up to " << array[rod_chosen] << " object(s). Please try again." << endl;
remove_read( array, rod_chosen);
}
}
int remove_read( int array[], int rod_chosen )
{
cout<< "Enter number of objects to remove (" << array[rod_chosesn] << " or less) from rod " << rod_chosen << ": ";
cin>> remove;
return (remove);
}
void modify( int array[], int rod_chosen, int remove)
{
array[rod_chosen] = array[rod_chosen] - remove;
}
void winner( int player)
{
cout<< "Congratulations! Player " << player << " wins." << endl;
}
void player_switch( int& player)
{
if ( player == 1)
{
player = 2;
}
else if (player == 2)
{
player = 1;
}
}