HW help?
Nov 13, 2014 at 7:11am UTC
So basically I need to write a program for blackjack the card game. my plan is to have 1 function get the number of cards, 2nd function add together the next line of values and then print the value or state that it's over 21. Currently my problem is that it doesn't print anything for my result. Please go easy on me, I know I suck at C++
j = jack
q = queen
k = king
a = ace
t = 10
My sample input that I must use is:
2
j j
3
q k j
4
2 5 t 2
5
5 5 5 2 2
4
5 3 k q
3
a a a
2
a a
4
a a 8 2
3
a k q
2
a t
2
a q
3
f t 3
5
g 3 5 2 3
2
l k
3
j k q
-99 // that "-99" is suppose to be for ending the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#include<fstream>
#include<cmath>
#define in_file "data.txt"
#define out_file "result.txt"
using namespace std;
char choice;
int cards, value = 0, total = 0;
void numberofcards(int &);
void card_total(char , int , int , int &);
int main ()
{
ifstream ins;
ofstream outs;
ins.open(in_file);
outs.open(out_file);
while (ins != "-99" )
{
numberofcards(cards);
card_total(choice, value, cards, total);
if (total <= 21)
{
outs << total << endl;
}
else if (total > 21)
{
outs << "Busted" << endl;
}
}
ins.close();
outs.close();
}
void numberofcards(int & cards)
{
ifstream ins;
ofstream outs;
ins.open(in_file);
outs.open(out_file);
ins >> cards;
switch (cards)
{
case '2' :
cards = 2;
break ;
case '3' :
cards = 3;
break ;
case '4' :
cards = 4;
break ;
case '5' :
cards = 5;
break ;
}
}
void card_total(char choice, int value, int cards, int & total)
{
ifstream ins;
ofstream outs;
ins.open(in_file);
outs.open(out_file);
while (ins >> cards)
{
switch (choice)
{
case '2' :
value = 2;
total = total + value;
break ;
case '3' :
value = 3;
total = total + value;
break ;
case '4' :
value = 4;
total = total + value;
break ;
case '5' :
value = 5;
total = total + value;
break ;
case '6' :
value = 6;
total = total + value;
break ;
case '7' :
value = 7;
total = total + value;
break ;
case '8' :
value = 8;
total = total + value;
break ;
case '9' :
value = 9;
total = total + value;
break ;
case 't' :
value = 10;
total = total + value;
break ;
case 'j' :
value = 10;
total = total + value;
break ;
case 'q' :
value = 10;
total = total + value;
break ;
case 'k' :
value = 10;
total = total + value;
break ;
case 'a' :
value = 11;
total = total + value;
if (total > 21)
{
value = 1;
}
break ;
}
}
}
Topic archived. No new replies allowed.