#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
srand(static_cast<unsignedint>(time(0)));
constint EASY_KILL_MULTIPLIER = 100;
constint NORMAL_KILL_MULTIPLIER = 200;
constint HARD_KILL_MULTIPLIER = 400;
constint 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.
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;