Hey all! How would you write write this code?

Write a C++ program using variables and loops in order to implement the Hi-Low strategy of card counting and keep a running count. The Hi-Low strategy of card counting assigns one of three values to a card, based on its face value. The table below breaks down these values. FACE VALUE ASSIGNEDVALUE 2, 3, 4, 5, 6 +1 7, 8, 9 0 10, J, Q, K, A -1 In a typical game of Blackjack, a card counter will start with a fresh deck and a count of 0. Each time a card is played, its assigned value is added (or subtracted) from what is known as the running count. The running count rolls over from hand to hand. For instance, if the first 7 cards of a game were: Queen, Jack, 4, 6, 7, Jack, 9, then the running count would be (0) -1 -1 + 1 + 1 + 0 –1 + 0 =-1

Respuesta :

The program is an illustration of loops.

Loops are used to perform repetitive actions.

The program in C++ where comments are used to explain each line, is as follows:

#include <string>

#include <iostream>

using namespace std;

int main(){

   //This declares all variables

   int n, count = 0; string k;

   //This gets input for the number of cards

   cin>>n;

   //The following is repeated n-times

   for(int i = 0;i <n;i++){

       //This gets input for the current card value

       cin>>k;

       //If the card is a digit

       if(isdigit(k[0])){

           //This checks if the card number is between 2 and 6 (inclusive)

           if(stoi(k) >= 2 && stoi(k) <= 6){

               //If yes the face value is increased by 1

               count+=1;

           }

           //This checks if the card number is 10

           else if(stoi(k) == 10){

               //If yes the face value is decreased by 1

               count-=1;

           }

       }

        //This checks if the card number is J, Q, K or A

       else if (k == "J" || k == "Q" || k == "K" || k == "A") {

           //If yes the face value is decreased by 1

           count-=1;

       }

   }

   //This prints the face value

   cout<<count;

   return 0;

}

At the end of the program, the face value is printed.

Read more about similar programs at:

https://brainly.com/question/24578223

ACCESS MORE
EDU ACCESS