C++ number genarator

Trying to create a simple battle menu game with a random number genarator from 1-10 for the extra hit points. but when i have tried to combined the users command from either 1 or 2 it says that i haven't created the number generator and its not clarified yet. Is there anything i am doing wrong or have to change.

#include <time.h> // for time()
#include <stdlib.h> // for system()
#include "pch.h"
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

float userAnswer;

int generateRandomValue() {
int range = (10 - 1) + 1;
// establash 'window' size
return rand() % range + 1;
// slide the window
}

int main() {

cout << "Player HP: " << endl; // *addiing hit points for player should be 100
cout << "Enemy HP : " << endl; // ** " "
cout << "Select an action..." << endl; // this is already set
cout << "1.) Attack" << endl; // *** set 1 as attack and combined the random value gen to it
cout << "2.) Heal" << endl; // **** set 2 as heal option to heal player also random value gen to it
cout << ":";
cin >> userAnswer; // where the user will place there answer
cout << userAnswer;
return 0;
}
Does this build? If it doesn't build, what is the error message?

If it does build, when you run it, what does it do that you don't want it to do, or what does it not do that you wish it did?

The code builds out fine, there is no error message with it. All that i am trying to do is take the "userAnswer" (either 1 or 2) and then it takes that and makes a random number and that then displays the number of hit points the player deals.
Well then you need to compare the user answer with '1' and if it's true, then you need to call the function.

It basically looks like you just haven't actually written any code to look at the user input and do something about it. Sometihng like this:

1
2
3
4
if (userAnswer == 1)
{
  int randomValue = generateRandomValue();
  // Now do something with that random value 


Also, don't user float if you're going to compare it to things where exact values matter. float is a very bad choice when exact values matter.
Thank you for the help!
Topic archived. No new replies allowed.