Help with the do while loop

I have this program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
	srand(static_cast<unsigned int>(time(0)));

	const int EASY_KILL_MULTIPLIER = 100;
	const int NORMAL_KILL_MULTIPLIER = 200;
    const int HARD_KILL_MULTIPLIER = 400;
    const int HARDCORE_KILL_MULTIPLIER = 700;
    int RANDOM_KILLS = rand() % 15 + 8;
    int score1 = RANDOM_KILLS * EASY_KILL_MULTIPLIER;
    int score2 = RANDOM_KILLS * NORMAL_KILL_MULTIPLIER;
    int score3 = RANDOM_KILLS * HARD_KILL_MULTIPLIER;
    int score4 = RANDOM_KILLS * HARDCORE_KILL_MULTIPLIER;
    string userInput;

    do{
    cout << "Please choose a difficulty: Easy, Normal, Hard, Hardcore" << endl;
    cin >> userInput;

    if(userInput == "Easy")
    {
        cout << "You chose Easy - your multiplier is x100";
            cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
                cout << "\nYour final score is: " << score1 << endl;
    }
    if(userInput == "Normal")
    {
        cout << "You chose Easy - your multiplier is x200";
            cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
                cout << "\nYour final score is: " << score2<< endl;
    }
    if(userInput == "Hard")
    {
        cout << "You chose Easy - your multiplier is x400";
            cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
                cout << "\nYour final score is: " << score3 << endl;
    }
    if(userInput == "Hardcore")
    {
        cout << "You chose Easy - your multiplier is x700";
            cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
                cout << "\nYour final score is: " << score4 << endl;
    }

        cout << "Do you want to play again? (Yes/No)" << endl;
        cin >> userInput;
  }while(userInput == "Yes");

}

The program generates a random and multiplies it depending on what difficulty the user chose.
I wanted to put it into a do while loop to repeat the program again, but I have this problem: Because a random number has already been generated, it loops again using the same number. So how can I make it so it generates a new random number.
Put the RANDOM_KILLS = rand() % 15 + 8; statement inside the loop. Then each iteration a new number is generated.
Stick lines 16 to 20 inside of the loop.
Do generate the random no. inside the DO WHILE block. This should work fine,

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
srand(static_cast<unsigned int>(time(0)));

const int EASY_KILL_MULTIPLIER = 100;
const int NORMAL_KILL_MULTIPLIER = 200;
const int HARD_KILL_MULTIPLIER = 400;
const int HARDCORE_KILL_MULTIPLIER = 700;

string userInput;

do{
cout << "Please choose a difficulty: Easy, Normal, Hard, Hardcore" << endl;
cin >> userInput;
int RANDOM_KILLS = rand() % 15 + 8;

if(userInput == "Easy")
{
cout << "You chose Easy - your multiplier is x100";
cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
int score1 = RANDOM_KILLS * EASY_KILL_MULTIPLIER;
cout << "\nYour final score is: " << score1 << endl;
}
if(userInput == "Normal")
{
cout << "You chose Easy - your multiplier is x200";
cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
int score2 = RANDOM_KILLS * NORMAL_KILL_MULTIPLIER;
cout << "\nYour final score is: " << score2<< endl;
}
if(userInput == "Hard")
{
cout << "You chose Easy - your multiplier is x400";
cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
int score3 = RANDOM_KILLS * HARD_KILL_MULTIPLIER;
cout << "\nYour final score is: " << score3 << endl;
}
if(userInput == "Hardcore")
{
cout << "You chose Easy - your multiplier is x700";
cout << "\nWell done you killed: " << RANDOM_KILLS << " enemies";
int score4 = RANDOM_KILLS * HARDCORE_KILL_MULTIPLIER;
cout << "\nYour final score is: " << score4 << endl;
}

cout << "Do you want to play again? (Yes/No)" << endl;
cin >> userInput;
}while(userInput == "Yes");
}
Thanks guys! Really appreciate it :D
Topic archived. No new replies allowed.