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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

in C++

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 and 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.
Transcribed Image Text: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 and 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.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education