Code
//Lab 4-1
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void)
{
//Variable Declarations
int total = 0;
char card;
char card1;
char card2;
char card3;
char counter=0;
//Description of the the program to the user instructing them how to enter the cards
cout << "This program is based off a game called black jac"
<< "\nPlease enter T for Ten, J for Jack, Q for Queen, K for King, and A for Ace."
<< "\nPlease enter the number value of the card for the rest."
<< "\nPlease enter only 1 digit or character"<< endl <<endl;
//Calculations for card 1, testing and card value outputs.
while (counter<=2)
{
cout << "\tEnter a card: ";
cin >> card;
if (counter==0)
{
card1=card;
if (counter==1)
card2=card;
if (counter==2)
card3=card;
}
//Checking/Swaping the aces
if (card1=='a' || card1=='A')
{
if (card3=='a'||card3=='A')
swap(card1,card2);
else
swap(card1,card3);
}
switch (card)
{
case 't':
case 'T':
case 'k':
case 'K':
case 'q':
case 'Q':
case 'j':
case 'J':
total = total + 10;
break;
case 'A':
case 'a':
if (total >= 9)
{
total = total + 1;
}
else
{
total = total + 11;
}
break;
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
total = total + card - '0';
break;
default:
cout << "\n\tError: You have not entered a correct card number." <<endl<<endl;
return 0;
break;
counter++;
}
}
//Totals
cout << endl;
cout.width(28);
cout << "\n\t\tCard Value: "<<card1;
cout << "\n\t\tCard Value: "<<card2;
cout << "\n\t\tCard Value: "<<card2;
cout << "Total: " << total << endl<<endl;
return 0;
}
Can't figure out what Im doing wrong
It will all compile but it says card3 is being used without being initialized.
This post was edited by Speed93 on Oct 22 2012 08:23pm