Question

.. C++ Language 1. Write a program to roll a random character. Declare an enum with...


..

C++ Language

1. Write a program to roll a random character. Declare an enum with all the different character types in
your game. Then use the rand()to generate a random number between the min and max values of your
enum (e.g. if you have 4 character classes, then enum values are 0, 1, 2, 3). Finally, depending on the type
of character that was randomly selected, generate the rest of the stats, either randomly or hardcoded.


Example Output
Press enter to roll a random character...
Type: Warrior
HP: 93
MP: 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

enum Characters
{
    king, warrior, goblin, horse
};

int main()
{
    srand(time(NULL));
    cout<<"Press enter to roll a random character...";
    cin.get();
    int character = rand() % 4;//Generate a random character
    switch(character)
    {
        case king:    cout<<"Type: King
";
                        cout<<"HP: 200
";
                        cout<<"MP: 10
";
                        break;
        
        case warrior:  cout<<"Type: Warrior
";
                        cout<<"HP: 93
";
                        cout<<"MP: 1
";
                        break;
        
        case goblin:   cout<<"Type: Goblin
";
                        cout<<"HP: 40
";
                        cout<<"MP: 2
";
                        break;
        
        case horse:       cout<<"Type: Horse
";
                        cout<<"HP: 20
";
                        cout<<"MP: 0
";
                        break;
    }
    return 0;
}

SAMPLE OUTPUT:

Add a comment
Know the answer?
Add Answer to:
.. C++ Language 1. Write a program to roll a random character. Declare an enum with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT