Hello again everyone I'm designing a code now that just deals a five card poker hand when the user presses D. I have to use pass by reference for this which I have pretty much no understanding of. The books isn't to clear and I haven't found too many useful tutorials online. Some guidance would be excellent. Just to forewarn I'm aware that there is lots of errors in this i get somewhere around 50 when i compile but they all seem to be similar.
Code:#include "stdafx.h"
#include <iostream>
#include <ctime> // allows rand num gen to choose a "random" number from the clock
#include <string>
using namespace std;
void get_card(int&,int&);
int main()
{
int card, suit, val;
int ansr;
srand((unsigned) time(0)); // "seed" the random number generator
cout << "\n\nTo deal yourself a poker hand please press D." << endl;
cin << ansr;
switch (ansr)
{
case 'd':
case 'D':
int n = 5; // deal this many cards
for (int i = 0; i < n; i++)
{
card=get_card(suit,val)
}
default:
cout << "\n\nThanks for playing." << endl << endl;
}
return 0;
}
void get_card(int& suit,int& val)
{
int suit = rand() % 4;
int val = 1 + rand() % 13;
switch (val)
{
case 1:
cout << "Ace";
break;
case 11:
cout << "Jack";
break;
case 12:
cout << "Queen";
break;
case 13:
cout << "King";
break;
default:
cout << value;
}
switch (suit)
{
case 0:
cout << " of Spades" << endl;
break;
case 1:
cout << " of Hearts" << endl;
break;
case 2:
cout << " of Diamonds" << endl;
break;
case 3:
cout << " of Clubs" << endl;
}
return;
}