All pastes #428308 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-07 13:57 UTC
rendered paste body
#include <stdio.h>
#define ZERO 48
#define NINE 57
#define TRUE 1
#define FALSE 0
#define SPACE 32
#define TAB 11
#define ENTER 10

int main() {
      int c = 0;
      int count = 0;
      int i=0;
      int dicerolls[5];
      int precedingWhitespace = TRUE; //First char need no whitespace;
      int incorrectinput=0;
      int valuerange=0;
      int numbervalues=0;
//    int dicemenu=0; // for the dice menu

      printf("Please enter dice values:\n");
      while((c = getchar()) != EOF)
      {
          if(!((c >= ZERO && c <= NINE) || c==SPACE || c==ENTER)){
//                printf("Incorrect Input Format: %d\n", c);
                incorrectinput=1;
          }
          if(c >= ZERO && c <= NINE){
              c = c - 48;
              if(!(c >= 1 && c <= 6))
              {
//                  printf("Value out of Range.\n");
                  valuerange=1;

              }
              dicerolls[count] = c;
              count++;
              precedingWhitespace = FALSE;

              if(count != 5){
//                  printf("Incorrect Number of Values.\n");
                  numbervalues=1;
              }
              else if(c == SPACE || c == TAB)
              {
                  if(precedingWhitespace == FALSE)
                  {
                      precedingWhitespace = TRUE;
                  }
              }

          }

          i++;


      }
      printf("counter:%d\n",count);
      if (incorrectinput==1){
         printf("Incorrect Input Format\n");
         valuerange=0;
         numbervalues=0;
      }
      if (valuerange==1){
         printf("Value out of Range.\n");
         numbervalues=0;
      }
      if (numbervalues==1){
         printf("Incorrect Number of Values.\n");
      }
/*i=0;
while (i < 5){
printf("Your dice values are: %d\n", dicerolls[i]);
i++;
}
*/


/*
printf("Please choose:\n 1 - > Reroll some dice \n 2 - > Reroll all dice\n 3 - > Keep dice\n");
scanf("%d",&dicemenu);
printf("You chose: %d",dicemenu);
*/


                 return(0);
}