Originally Posted by
rTeapot
First question : the system("cls") I have read around and realize that system calls are often frowned upon, BUT I honestly can't think of a way to get this to "look like a slot machine" without clearing the window out each time, any ideas on how to do this without the system call? It does really slow it down and would be nice to be rid of...
Hmmm. I am not sure! Here's the FAQ: FAQ > Clear the screen? - Cprogramming.com
system() is indeed frowned upon for several good reasons (mentioned in the FAQ), so it's definitely best to avoid it if you can. I think you'll find that the slowdown introduced by the slow system() call is what makes your program "look like a slot machine" Without that performance penalty, the program will run so fast you won't get to see anything! So you'll need to introduce a delay.
It depends how serious you are about doing the right thing. I'd be tempted to just use system().... so long as you KNOW it's bad, it's not so bad maybe. *shudder* maybe someone else will have a better idea.
Originally Posted by
rTeapot
Second question : any ideas on how I could write the code better(shorter) for the rewards? I wish switches could take in multiple variable dependencies but alas they cannot :/.
You're currently testing all the numbers are the same, so you could just do:
Code:
if (num0 == num1 && num1 == num2)
{
cout << "You won " <<num0 <<"dollars. Congratulations!\n";
}
Nothing wrong with having a load of if statements, though since only one case will be true it'd be more normal to use:
Code:
if(cond)
..
else if (cond)
..
else if (cond)
If you wanted to define lots of different winning combos and have them in an easy to read layout, I'd probably go for holding the winning combinations in a 2D array or array of structs along with any supporting information (e.g. amount won), then writing the code to loop through the array.
Couple of code comments:
Code:
int main()
{
int num0;
int num1;
int num2;
for (int i = 0; i < 100; ++i)
{
srand (time(NULL));
You only need to call srand once - it shouldn't be in the loop.
Code:
int num0 = randNum0(1, 9);
int num1 = randNum1(1, 9);
int num2 = randNum2(1, 9);
I don't think this should work -- declaring num0,num1,num2 in the inner loop then using them in the outer loop. But apparently it does - anybody?
[edit] - ignore that last comment -- user error. It behaves as expected (i.e. the values are not valid outside of the for loop).