Advertisement
shadowlucario50

C++ Simple Stat Randomizer

Apr 26th, 2025
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. void hp(int base);
  5. void attack(int base);
  6. void defense(int base);
  7. void speed(int base);
  8.  
  9. int main(){
  10.     //Assignment: Create a unique function.
  11.     //Challenge: Calculate stats in other functions and return them.
  12.     srand(time(0));
  13.     int base_stat = 0;
  14.  
  15.     do{
  16.     std::cout << "Enter in a base stat (0-50): ";
  17.     std::cin >> base_stat;
  18.     if(base_stat > 50 || base_stat <= 0){
  19.         std::cout << "Stat not in range! ";
  20.         base_stat = 0;
  21.     }
  22.     }while (base_stat == 0);
  23.  
  24.     std::cout << "Stats\n";
  25.     hp(base_stat);
  26.     attack(base_stat);
  27.     defense(base_stat);
  28.     speed(base_stat);
  29.  
  30.     return 0;
  31.  
  32. }
  33.  
  34. void hp(int base){
  35.     base;
  36.     int hp = rand() % 11 + base + 30;
  37.     std::cout << "HP: " << hp << '\n';
  38. }
  39.  
  40. void attack(int base){
  41.     base;
  42.     int attack = rand() % 11 + base;
  43.     std::cout << "Attack: " << attack << '\n';
  44. }
  45.  
  46. void defense(int base){
  47.     base;
  48.     int defense = rand() % 11 + base;
  49.     std::cout << "Defense: " << defense << '\n';
  50. }
  51.  
  52. void speed(int base){
  53.     base;
  54.     int speed = rand() % 11 + base;
  55.     std::cout << "Speed: " << speed << '\n';
  56. }
Tags: C++ Code coding
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement