Question

In C++ Design and implement a program that rolls two dice. Ask the user to input...

In C++ Design and implement a program that rolls two dice. Ask the user to input a number between 2 and 12. Then, roll your dice by using a random function to generate a random number representing one of the sides. Output the result of each die and the combined total of the two sides. Continue rolling the dice until the total equals what the user entered. Output the number of tries it took.

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

using namespace std;

int main() {
    srand(time(nullptr));
    int count = 0, num, d1, d2;

    cout << "Enter a number between 2 and 12: ";
    cin >> num;

    while (true) {
        d1 = 1 + (rand() % 6);
        d2 = 1 + (rand() % 6);
        cout << "You rolled " << d1 << " and " << d2 << endl;
        count++;
        if(d1 + d2 == num) break;
    }

    cout << "It took " << count << " tries" << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
In C++ Design and implement a program that rolls two dice. Ask the user to input...
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