cout<<"Enter the value of the first card: ";
cin>>card1;
cout<<"Enter the value of the second card: ";
cin>>card2;
cout<<"Enter the value of the third card: ";
cin>>card3;
cout<<"Your score is: ";
if (card1==1 && card2==1)
cout<<23;
else if (card1==1)
cout<<11+ card1 + card2;
else if (card2==1)
cout<<card1+ 11 + card3;
else if (card3==1)
cout<<card1+ card2+ 11;
else if (result <= 21)
cout<<"Sorry you lose!"<<endl;
else if (result > 21)
cout<<"Congratulations you win!"<<endl;
You need to assign something to result, it will always be empty, until you put something in it. So you will have to change the last 2 'else if' statements, and you could do the calculations "11+card1+card2" into a different int, instead of in the cout function so something like this:
# include<iostream>
usingnamespace std;
int main ()
{
int card1,card2, card3, add0, add1, add2, add3, result;
cout<<"Enter the value of the first card: ";
cin>>card1;
cout<<"Enter the value of the second card: ";
cin>>card2;
cout<<"Enter the value of the third card: ";
cin>>card3;
cout<<"Your score is: ";
/* I added all the add0-3 into the if statements, and then made result equal to the
* add integers the addition of all the card1-3 and numbers you were adding inside
* the cout function have now been done in the add0-3 integers, so that the result
* can go into the result integer.
*/
if (card1==1 && card2==1)
{
add0=23;
cout<<23;
result=add0;
}
elseif (card1==1)
{
add1=11+card1+card2;
cout<<add1;
result=add1;
}
elseif (card2==1)
{
add2=card1+11+card3;
cout<<add2;
result=add2;
}
elseif (card3==1)
{
add3=card1+card2+11;
cout<<add3;
result=add3;
}
if (result <= 21) // I changed this to an if statement, because it doesn't go along
// with the other else if statements above
cout<<"Sorry you lose!"<<endl;
elseif (result > 21)
cout<<"Congratulations you win!"<<endl;
else
cout<<"there was an error" // I added this so it could tell you if there was a problem
// with the above two statements.
return 0;
}
This code is not guaranteed to work, I didn't run it, just added onto it, I haven't even compiled it either, I will in a bit and tell you if it comes out.