Please help me modify this program, assignment is due tonight at midnight

C++ Modify existing program

Step 1

2Add to code that after each hand of the game, ask the user if he/she wants to play another hand or not. If a ‘y’ is entered, the program should clear the display on the screen from the previous hand and then play the next hand (whether your program accepts upper case ‘Y’ or not is up to you); otherwise, it terminates.

3) Update the documentation part accordingly and re-compile/execute the program to ensure that you did not accidentally change any other part of the program.

Step 2

Enhance the program so that, after each hand of the game, it asks the user if he/she wants to play another hand or not. Now, assume that only ‘y’ or ‘n’ is a valid input (whether your program accepts upper case ‘Y’ or ‘N’ as a valid input is up to you). If a ‘y’ is entered, the program does the same thing as the previous version; if an ‘n’ is entered, the program should terminate; otherwise, the program should display “Invalid input. Enter only ‘y’ or ‘n’ please:” and have the user re-enter an answer until a valid input is entered. Compile and run the program. Correct any mistakes before proceeding.

3) Enhance the program further so that it also keeps track of the numbers of the total battles that have been played; battles that were won by you, by the opponent, tied, and the percentages in these three categories, respectively. The percentage in each category is equal to (battles in that category) / (total battles)*100. Display on screen these statistics at the end of each battle in the following format. A percentage number should be displayed in decimal notation in a field of 6 spaces with 2 decimal places. All numbers should be aligned correctly based on their significant digits. A sample output is shown at the end of the assignment.

4) Update the documentation part accordingly and re-compile/execute the program to ensure that you did not accidentally change any other part of the program.

[code]
#include
#include
#include
#include
using namespace std;

int main()
{
const int MIN_VALUE = 3; const int MAX_VALUE = 6; int suit; int suit2;
unsigned seed = time(0);
srand(seed);
suit = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
suit2 = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;

const int MIN = 2; const int MAX = 14; int num1; int num2;
unsigned seed1 = time(0);
srand(seed1);
num2 = (rand() % (MAX - MIN + 1)) + MIN;
num1 = (rand() % (MAX - MIN + 1)) + MIN;


cout << " "; cout << char(201); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(187) << endl;
cout << " "; cout << char(186); cout << " The Card Game: \"War\" "; cout << char(186) << endl;
cout << " "; cout << char(200); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(205); cout << char(188); cout << "\n\n\n";
cout << " Your Card Opponent's card \n";
cout << " "; cout << char(218); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(191); cout << " "; cout << char(218); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(191) << endl;

cout << " "; cout << char(179); if (num1 == 11); if (num1 == 12)cout << "Q"; if (num1 == 13)cout << "K"; if (num1 == 14)cout << "A"; else cout << num1; cout << " "; cout << char(179); cout << " "; cout << char(179); if (num2 == 11)cout << "J"; if (num2 == 12)cout << "Q"; if (num2 == 13)cout << "K"; if (num2 == 14)cout << "A"; else cout << num2; cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(suit); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(suit2); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179); cout << " "; cout << char(179) << endl;
cout << " "; cout << char(179); cout << " "; if (num1 == 11); if (num1 == 12)cout << "Q"; if (num1 == 13)cout << "K"; if (num1 == 14)cout << "A"; else cout << num1; cout << char(179); cout << " "; cout << char(179); cout << " "; if (num2 == 11)cout << "J"; if (num2 == 12)cout << "Q"; if (num2 == 13)cout << "K"; if (num2 == 14)cout << "A"; else cout << num2; cout << char(179) << endl;
cout << " "; cout << char(192); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(217); cout << " "; cout << char(192); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(196); cout << char(217) << endl;


}// if (num1 > 9) cout << " "; else
You could start with:
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
What is your actual question? It looks like you're spending too much time trying to make your output look pretty. Do less of that, more actual functionality.
You have the opening code tag. You just need to edit your post and add the closing code tag: [/code]

What's with the empty includes?

Do not call srand() multiple times. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause the RNG to return the same random numbers. srand() should be called ONCE at the beginning of main().
http://www.cplusplus.com/reference/cstdlib/srand/

Using the decimal values of the box drawing set makes your code hard to read.
Using enums makes it clear in the code what you're trying to draw.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
enum class EXT_ASCII : char
{
    VERT_BAR = 179,
    RIGHT_T = 180,
    UPPER_R = 191,
    LOWER_L = 192,
    BOTTOM_T = 193,
    TOP_T = 194,
    LEFT_T = 195,
    HORIZ_BAR = 196,
    CROSS = 197,
    LOWER_R = 217,
    UPPER_L = 218
};
Last edited on
I know that the code is sloppy and I will try to work on it but can anyone just type the parts I need help with and I can add them to the code?
your tutor wrote:

Step 1
2) Add to code...
3) Update the documentation...

Step 2
x) Enhance the program...
3) Enhance the program further...
4) Update the documentation...

The point of the exercise is not to just show up at the end with the finished result.
It's all about the experience of writing software in incremental steps, testing as you go.

Just giving you the answer won't convey that experience.

It's like eating at a restaurant, and then expecting that will tell you how to cook.
You know what the end result looks like, but you've NO idea how to get there yourself.

> assignment is due tonight at midnight
By failing to prepare, you're preparing to fail.
https://en.wikipedia.org/wiki/Procrastination
http://catb.org/~esr/faqs/smart-questions.html#urgent
at midnight

UTC or Zulu time? (We don't want to help too early.)
Topic archived. No new replies allowed.