Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int cal(int i){
- // Passes i by value, not reference.
- // subtract 10 from it.
- i-=10;
- // Basic math
- if(i>0)return i/2;
- if(i<0)return ((i-1)/2);
- return 0;
- }
- void pv(char *s, int v){
- // Print 'newline' then S then V
- printf("\n%s: %d ",s,v);
- // If cal returned 0, print 0
- // otherwise force add a '+' or '-' sign
- // (depending on the number)
- // infront of it and print the number.
- if(cal(v)==0) printf("0");
- else printf("%+d", cal(v));
- }
- void rdv(char *s, int *i){
- printf("Enter %s: ",s);
- // check for valid input
- // if valid, store it in variable d
- if(scanf("%d",i)!=1){
- printf("Enter Valid Input\n");
- // Wait until user hits enter
- while(getchar()!='\n');
- // Basically loops the function until a user enters a valid input
- rdv(s, i);
- }
- }
- int main() {
- // Enter a seed the random number generator
- srand((unsigned)time(NULL));
- int Str,Dex,Con,Int,Wis,Cha,Level;
- rdv("Str", &Str);
- rdv("Dex", &Dex);
- rdv("Con", &Con);
- rdv("Int", &Int);
- rdv("Wis", &Wis);
- rdv("Cha", &Cha);
- rdv("Level", &Level);
- printf("\nLevel: %d",Level);
- pv("Str", Str);
- pv("Dex", Dex);
- pv("Con", Con);
- pv("Int", Int);
- pv("Wis", Wis);
- pv("Cha", Cha);
- // prints 'newline' HP: (some number)
- // Level * (randomNumberLessThan6 + 1)
- printf("\nHP: %d",Level*((rand()%6+1)));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement