I'm doing this slot machine game where a 3x3 2D-array is being generated with random letters. I have successfully made the game work as I want but I wonder if you have any tips on how I can optimize or improve my code.
What I've gotten my code to do:
- Generate an 2D-array (3x3) and randomly assign chars out of 3 letters.
- An "if" that will compare and see what elements in the array belong to each other (same char next to eachother for getting columns/rows/diagonals).
- An "if else" that will take total amount of columns/rows/diagonals and make a prize out of it, depending on total amounts of row in the slot machine and the bet.
So I'm now wondering if you have any suggestions on how I can improve the "if" code where the program checks if there are any rows/columns/diagonals? The game works as it should but I just wonder if there's any way of optimizing it - Perhaps with a "for-loop"? I also wonder if you have any tips on the "prize" code where the code calculates total amout of rows/columns/diagonals and multiplies that with the bet.
I mean, there must be a way to optimize this. If I was to do a 100x100 array, the code where the elements are compared would be awfully long :) I'm new to C++ (this is a course) so I'm looking forward to optimize this.
PS! I'm not asking for a solution but rather suggestions/tips of methods I can use to optimize it. This is a homework so no solutions please, only suggestions/tips!
My code for the array comparison and prize calculation: