Hello
Was hoping if anyone can help me with making this program its for my midterm what I have to do is make a card game using voids and vectors just the basic things when starting C++
My game that I'm try to make is called 24
The basics of the game is that the user and the computer get 4 random cards from a std deck of 52 jacks are taken out
each card has a value from 1 to 11
The point of the game is to get 24 with the numbers that were given using +, , / , *
the player has to input what they want to do
but yehh that's what have to do
I might be explaining it wrong
here's the Link for the game and its better explain
http://www.pagat.com/adders/24.html
if anyone wants to see what i have I'll give it if anyone who needs to look at it that's if anyone gets it
thanks
C++ 
+4  Sebastian Anthony Fernandez · February 17, 2015 
Post a Reply 
Replies 
Oldest Newest Rating 
0 
Sebastian Anthony Fernandez
· February 17, 2015
The only way the user win is if they get a 24

+1 
Abdullah Nauman
· February 17, 2015
Still, the computer would win.

0 
Sebastian Anthony Fernandez
· February 18, 2015
No what i mean is that ones the player knows what there going to do (+,,*,/)
they'll press enter now with the computer i want to randomizes what the computer does so it won't get the right answer all the time to make it fair here's the Algorithm The computer way to play this game is to: get all possible permutations of 4 numbers, calculate all possible arithmetic results for each permutation, and then judge whether 24 is within the result set. Step 2 is the core of the algorithm. Let's assume a sorted permutation from step 1 is expressed as A1, A2, A3, ..., An. Define F as F (An) = A1 (op) A2 (op)A3, ... An1 (op) An, where (op) is addition (+), subtraction (), multiplication (*) or division (/), reverse subtraction or reverse division. It's natural that F (An) = F (An1) (op) An. This is where a recursive function shows its power. now here's what the player needs to do The rule is simple: at random any 4 cards, and try to get a result of 24 from the numbers on the cards, only with the 4 basic arithmetic operations, namely, addition (+), subtraction (), multiplication (*) and division (/). Jack (J), Queen (Q), King (K) and Ace (A) represent 11, 12, 13 and 1 respectively, or they all represent 1 in an alternative flavor. For example, given numbers 3, 3, 4 and 8, we can get such an expression: 3*8*(43) = 24. 
0 
Sebastian Anthony Fernandez
· February 20, 2015
its still not done but here's what i got
#include <iostream> #include <string> #include <cstdlib> #include <vector> #include <ctime> using namespace std; void DisplayText(); void DisplayRules(); void Display1(vector<int>, vector<int>); void DealCard(vector<int>&,vector<int>&,vector<int>&); void GenDeck(vector<int>&); void Menu(); void Switch(vector<int>& vec,vector<int>& vec3); int main() { vector<int> player; vector<int> compter; vector<int> deck; vector<int> cla; DisplayText(); DisplayRules(); cout << "your numbers are" << endl; GenDeck(deck); DealCard(deck,player,compter); Display1(player, compter); Menu(); Switch(player, cla ); system("pause"); return 0; } void DisplayText() { cout << "Welcome to 24" << endl; cout << "In order to win you must get 24" << endl; } void DisplayRules() { cout << "Now with these numbers use +, , *, / to get 24 to win the game!!! " << endl; } void GenDeck(vector<int>& deck) { for (int i=1; i<=13; i++) { for (int j=0; j<4; j++) { deck.push_back(i); } } srand(static_cast<unsigned int>(time(0))); } void Display1(vector<int>vec, vector<int>vec2) { cout << "Player hand : (" << *vec.begin() << "_" << *vec.begin()+1 << ") " << *vec.begin()+2 << " " << *vec.begin()+3 << endl; cout << "Comtper hand : (" << *vec2.begin() << "_" << *vec2.begin()+1 << "_" << *vec2.begin()+2 << "_" << *vec2.begin()+3 << endl; } void DealCard(vector<int>& deck,vector<int>& vec,vector<int>& vec2) { for (int i=0; i<4; i++) { vec.push_back(*deck.begin()); deck.erase(deck.begin()); vec2.push_back(*deck.begin()); deck.erase(deck.begin()); } } void Menu() { cout << "Enter '1' to +.\nEnter '2' to .\nEnter '3' to *.\nEnter '4' to /.\nEnter '5' to back out of game." << endl; } void Switch(vector<int>& vec,vector<int>& vec3) { int Menu; cin >> Menu; switch (Menu) { case 1: vec3.push_back(*vec.begin() + *vec.begin()+1); // Card 1 + Card 2 case 2: vec3.push_back(*vec.begin()  *vec.begin()+1); // Card 1  Card 2 case 3: vec3.push_back(*vec.begin() * *vec.begin()+1); // Card 1 * Card 2 case 4: vec3.push_back(*vec.begin() / *vec.begin()+1); // Card 1 / Card 2 } } 
0 
Sebastian Anthony Fernandez
· February 21, 2015
trying to get the computer to work and trying to get the random card to work cuz it still don't work
need help with a lot 
0 
Sebastian Anthony Fernandez
· February 22, 2015
alright how would u write it out?

0 
a syafiq
· February 25, 2015
wont it be easier to make a text based game if youre using only the basics of c++? just wondering

 1