You are writing a card game loosely modeled on the classic game "WAR". Your partner starts with a deck of cards that they turn over one at a time. If they enter an ace (marked as 1), you will take the two bottom cards from their pile. If they enter any classic face card, which is a Jack (11), Queen (12), or King (marked as 13), you will take two cards from the top of their pile. The game ends when they turn over a Joker, marked as a 14. Whoever has more cards wins. The way you will turn this into code is to write a program (i.e. main function) that asks the user to repeatedly enter positive integers between 1 and 14, stopping when the user enters 14. If a number outside of this range is entered, the program should output "The number must be between 1 and 14", and then prompt the user for the next number. You need to use a vector in this question to store your partners cards, and a counter to store your own. At the beginning of the program, the vector is empty. Then, as the user enters values, the vector will be updated based on the following conditions in this order (1, 2, 3, 4): 1. Add the card value to the vector. 2. If the card value is 1, remove the two element from the start of the vector and increment your counter by two. If there is only one card in the vector, only remove that card and increment the counter by one. 3. If the card value is 11, 12, or 13, remove the element from the end of the vector. increment your counter. If there is only one card in the vector, only remove that card and increment the counter by one. 4. If the card value is 14, remove the card from the vector but do not increment your counter. After the Joker is added, your program should display all elements in the vector, in order, separated by spaces. On the next line, you should print the counter. You will then compare your counter to the size of your vector to determine the victor. 1. If the counter is higher than the vector length, print "I win!" 2. If the counter is lower than the vector length, print "You win!" 3. If the counter is equal to the vector length, print "Tie!" Paste your entire program, including libraries and main(), in the answer box below.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
in C++
Step by step
Solved in 4 steps with 4 images