Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int cal(int i){
  6.  
  7. // Passes i by value, not reference.
  8. // subtract 10 from it.
  9.  
  10.     i-=10;
  11.  
  12. // Basic math
  13.  
  14.     if(i>0)return i/2;
  15.     if(i<0)return ((i-1)/2);
  16.     return 0;
  17. }
  18.  
  19. void pv(char *s, int v){
  20.  
  21. // Print 'newline' then S then V
  22.  
  23.     printf("\n%s: %d ",s,v);
  24.  
  25. // If cal returned 0, print 0
  26. // otherwise force add a '+' or '-' sign
  27. // (depending on the number)
  28. // infront of it and print the number.
  29.  
  30.     if(cal(v)==0) printf("0");
  31.     else printf("%+d", cal(v));
  32. }
  33. void rdv(char *s, int *i){
  34.  
  35.     printf("Enter %s: ",s);
  36.  
  37. // check for valid input
  38. // if valid, store it in variable d
  39.  
  40.     if(scanf("%d",i)!=1){
  41.  
  42.         printf("Enter Valid Input\n");
  43.  
  44.         // Wait until user hits enter
  45.  
  46.         while(getchar()!='\n');
  47.  
  48.         // Basically loops the function until     a user enters a valid input
  49.  
  50.         rdv(s, i);
  51.     }
  52. }
  53. int main() {
  54.  
  55. // Enter a seed the random number generator
  56.  
  57.     srand((unsigned)time(NULL));
  58.  
  59.     int Str,Dex,Con,Int,Wis,Cha,Level;
  60.     rdv("Str", &Str);
  61.     rdv("Dex", &Dex);
  62.     rdv("Con", &Con);
  63.     rdv("Int", &Int);
  64.     rdv("Wis", &Wis);
  65.     rdv("Cha", &Cha);
  66.     rdv("Level", &Level);
  67.  
  68.     printf("\nLevel: %d",Level);
  69.  
  70.     pv("Str", Str);
  71.     pv("Dex", Dex);
  72.     pv("Con", Con);
  73.     pv("Int", Int);
  74.     pv("Wis", Wis);
  75.     pv("Cha", Cha);
  76.  
  77. // prints 'newline' HP: (some number)
  78. // Level * (randomNumberLessThan6 + 1)
  79.  
  80.     printf("\nHP: %d",Level*((rand()%6+1)));
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement