Hey guys and gals, hows it going? Hopefully a very quick and easy question. This code:
Is throwing the error: uninitialized local variable 'playerStats' used
for the playerStats reference in the infinite while loop....why? Its initialized right there at Stat playerStats; .
Also Intellisense (yes I'm using visual studio 2010, I'm on my Ultrabook and linux hates this hardware) is saying "more than one instance of overloaded function "statLineGen" matches the argument list." Which doesn't make sense because I've only prototyped one statLineGen.
Its probably a really stupid error as I'm just now getting back into C++ after a fairly lengthy break. Tossing it the Fedora camp since I trust you guys more than I do stackoverflow or TechNet
EDIT: Copy paste butchered the whitespacing of my code and trying to fix it doesn't seem to helping. Just wanted to say that THAT wasn't actually my whitespacing.
Code:
#include <iostream>
#include <time.h>
#include <cstdlib>
using namespace std;
struct Stat {
int rollOne;
int rollTwo;
int rollThree;
int rollFour;
int rollsTotal;
};
int createRandomNumber();
void statLineGen(Stat);
int main()
{
srand(time(NULL));
Stat playerStats;
cout << "Press any key to begin calculating sets of stat values." << endl;
cout << "Program will pause after every line, press any line to display next line." << endl << endl;
while(1)
{
statLineGen(playerStats);
cin.get();
}
return 0;
}
int createRandomNumber()
{
int randNumber = rand() % 6 + 1;
return randNumber;
}
void statLineGen(Stat &playerStats)
{
for(int x=1; x<=6; x++)
{
playerStats.rollOne = createRandomNumber();
playerStats.rollTwo = createRandomNumber();
playerStats.rollThree = createRandomNumber();
playerStats.rollFour = createRandomNumber();
playerStats.rollsTotal = playerStats.rollOne + playerStats.rollTwo + playerStats.rollThree + playerStats.rollFour;
playerStats.rollsTotal = playerStats.rollsTotal - min(playerStats.rollOne,min(playerStats.rollTwo,min(playerStats.rollThree,playerStats.rollFour)));
cout << playerStats.rollsTotal << "\t";
}
cout << endl;
}
for the playerStats reference in the infinite while loop....why? Its initialized right there at Stat playerStats; .
Also Intellisense (yes I'm using visual studio 2010, I'm on my Ultrabook and linux hates this hardware) is saying "more than one instance of overloaded function "statLineGen" matches the argument list." Which doesn't make sense because I've only prototyped one statLineGen.
Its probably a really stupid error as I'm just now getting back into C++ after a fairly lengthy break. Tossing it the Fedora camp since I trust you guys more than I do stackoverflow or TechNet
EDIT: Copy paste butchered the whitespacing of my code and trying to fix it doesn't seem to helping. Just wanted to say that THAT wasn't actually my whitespacing.