I got a guy to help me with it, it turn's out that getline doesn't jive well with cin, simply changing that cin >> input instead fixed problem one. He has also shown me how to allocate the array memory to heap instead of stack, though this confuses me but i just about get it, just about, and it works the same as before, using new ** as the declaration. This, he has told me, creates a memory leak every time you change the size of the array, which isn't too bad as it is under control and part of a small program, but I want to then delete that array as you apparently SHOULD do when creating a dynamic array and no longer need it, which is only a line or two at the end of my main game loop, but I will figure that out later. My scoring system now works as well, it checks the bonus ball and adds 1 to the score to flag a bonus match, I think this was fixed by making the Matches array which holds the score for each line, ALSO dynamic (but only one dimensionally this time). Whatever it was, it works perfectly now.
Now I am just short a few simple features. I will need to close the memory leak by my two size changing arrays, but for now, I absolutely NEED to get a bubble sort on each line working, so you can input your numbers on the line in any order, but the print in ascending order. My bubble sort is below, it runs just before the usual printing thread, so it should re order each line, then print each line, but it doesn't work for some reason. It compiles, it just doesn't DO the bubble sort.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
//---BUBBLE SORT CODE-------------------------------------
for(int Line = 0; Line < Lines; Line++)
{
int flag = 1;
for(int n = 0; n < 6 && flag; n++)
{
flag = 0;//resets flag
for (int bs = 0; bs < (n - 1); bs++)
{
if(Guess[Line][n+1] < Guess[Line][n]) //if the next in the array is less than this one
{
int temp;
temp = Guess[Line][n]; //swap elements using temp data storage
Guess[Line][n] = Guess[Line][n+1];
Guess[Line][n+1] = temp;
flag = 1; //indicates that a swap occurred.
}
}
}
}
|
And the second, and I think final, functionality I absolutely, definitely NEED, is to check for and prevent duplicate numbers from appearing A) within each Line and B) From any of the bonus balls. I imagine this will be a simple loop statement but my code is so confusing now I'm not sure where to put it and how it will work, without breaking the rest of the program. I will have a go at it in the meantime, but hopefully someone will be ready to help me with it soon when it inevitably doesn't do what it looks like it should do ;P
in case it helps, I will post the random number generator, and someone can show me how to check for duplicates within that, that would be awesome. I understand that it needs to generate Ball[1], then generate Ball[2], check if it is the same as Ball[1], and if it is, then regenerate Ball[2] until it is not the same as Ball[1]. Then it needs to generate Ball[3], compare it to ball[2], if it is the same, regenerate, if not, compare it to Ball[1], and same deal, and so on in the fashion. I just don't know what type of loop I will need to do this best.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void Generate(int *Ball, int &BonusBall)
{
cout << "Lets get those balls rolling...\n\n";
srand ( time(NULL) );
for(int n = 0; n < 6; n++)
{
do
{
Ball[n] = rand() % BetHigh + BetLow;
}
while(Ball[n] < BetLow || Ball[n] > BetHigh);
cout << Ball[n] << "\t";
}
BonusBall = rand() % BetHigh + BetLow;
cout << "And the bonus is..... " << BonusBall << endl << endl;
}
|
(nevermind about the deleting array thing, I think I've got it by simply making a loop asking if the user wants to reuse the same ticket, and if they don't, to delete Guess; and delete Matches; after the loop breaks, before going back up to the top to start from entering number of lines again. I love how clever I've literally gotten over night! Still need help with bubble sort and preventing duplicates from the machine though. once I figure out how to stop dupes coming out the machine, I can apply that to the numbers on each line preeeetty easily, then it's simply a case of changing BetHigh from 10 to 49, and starting the Wallet with 50 instead of 15, and my game will be fully functional! YAY!)
Thanks again everyone here, such a great community, I am a new lover of programming, I wouldn't be as good and I wouldn't enjoy it as much if it wasn't for all the help and support I've been getting from all over the place, and I am grateful for it =]