Hi
i wonder if anyone can help me.
i am not getting the desired output for the if statements that have to deal with the aces function.
i want it to output "2 or 22" if aces+aces is the input etc.
please help
#include <iostream>
#include <string>
using namespace std;
int cardVal()
{
string card;
cin >> card;
if(card == "Kc" || card == "Kd" || card == "Kh" || card == "Ks" ||
card == "Qc" || card == "Qd" || card == "Qh" || card == "Qs" ||
card == "Jc" || card == "Jd" || card == "Jh" || card == "Js" ||
card == "10c" || card == "10d" || card == "10h" || card == "10s")
{
return 10;
}
else if(card == "9c" || card == "9d" || card == "9h" || card =="9s")
{
return 9;
}
else if(card == "8c" || card == "8d" || card == "8h" || card =="8s")
{
return 8;
}
else if(card == "7c" || card == "7d" || card == "7h" || card =="7s")
{
return 7;
}
else if(card == "6c" || card == "6d" || card == "6h" || card =="6s")
{
return 6;
}
else if(card == "5c" || card == "5d" || card == "5h" || card =="5s")
{
return 5;
}
else if(card == "4c" || card == "4d" || card == "4h" || card =="4s")
{
return 4;
}
else if(card == "3c" || card == "3d" || card == "3h" || card =="3s")
{
return 3;
}
else if(card == "2c" || card == "2d" || card == "2h" || card =="2s")
{
return 2;
}
}
int aces()
{
string card;
cin >> card;
if(card == "Ac" || card == "Ad" || card == "Ah" || card == "As")
{
return 1;
}
}
int main()
{
int sum = 0;
if(sum = cardVal() + cardVal())
{
cout << sum << endl;
}
else if(sum = aces() + aces())
{
cout << sum << " or " << sum + 20 <<endl;
}
else if(sum = aces() + cardVal())
{
cout << sum << " or " << sum + 20 << endl;
}
else if(sum = cardVal() + aces())
{
cout << sum << " or " << sum + 20 << endl;
}
else if(sum == 21)
{
cout << "Blackjack !" <<endl;
}
return 0;
}