Please help me C I posted this question before but the given

Please, help me (C++). I posted this question before but the given program did not work properly. It is a game of blackjack where we need to input files (input.txt) and need to output our result to a txt file. Our prof has given us a skeleton code to work with. I can provide more info if needed. Thanks!

10 10 J 10 Q 10 K-10 So basically each card is worth the value on the face, 2 10. The Jack, Queen, King are also worth 10. The Ace is worth either 1 or 11. lf you read an Ace, or A, and the sum for the player is is such that you can add 11 and not bust, then you add 11. lf adding 11 would bust the player, then you add 1, regardless of what it does to the sum e. bust the player or not. If you\'ve read an Ace and added it as 11, you wi not go and change the value to a 1 later if the player busts. Output The output will be generated in your program in the loop that is reading in the data. I\'ll show an example below: Player one\'s cards QA Player two\'s cards A 7 Game Over Player one won Player one sum 21 Player two sum: 18

Solution

#include \"project1.h\"

using namespace std;

void blackjack(string inputfilename, string outputfilename){
    string card;
    ifstream in(inputfilename);
    ofstream out(outputfilename);
    in >> card;
    int sum=0;
    int cardInt=0;
    int player[2];
    int playerIndicator=0;
    while (!in.fail()){
        cout << \"Player one\'s cards: \";
      
        if((card==\"J\")||(card==\"Q\")||(card==\"K\")){
            sum+=10;
            cout << card+\" \";
        } else if(card==\"A\"){
            if(sum+11>21) sum+=1;
            else sum+=11;
            cout << card+\" \";
        } else{
            stringstream convert(card);
            convert>>cardInt;

            sum+=cardInt;
            cout << card+\" \";
        }
      
        if(sum>=17){
            player[playerIndicator]=sum;
            playerIndicator++;
        }
        if(playerIndicator>1)
            break;
        else if(playerIndicator==1){
            out << endl<<\"Player two\'s cards: \";
        }
        in >> card;
    }
    out << \"Game Over\" << endl;
    if(player[0]>player[1] && player[0]<=21){
    out << \"Player one won\" << endl;
    } else if(player[1]>player[0] && player[1]<=21){
    out << \"Player two won\" << endl;
    } else if(player[0]>21 && player[1]>21){
    out << \"Everyone busted\" << endl;
    } else if(player[0]==player[1]){
    out << \"Push\" << endl;
    }
    out << \"Player one\'s sum: \"+player[0] << endl;
    out << \"Player two\'s sum: \"+player[1] << endl;
    in.close();
    out.close();
}

Please, help me (C++). I posted this question before but the given program did not work properly. It is a game of blackjack where we need to input files (input.
Please, help me (C++). I posted this question before but the given program did not work properly. It is a game of blackjack where we need to input files (input.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site