Guest User

Untitled

a guest
Jan 24th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.04 KB | None | 0 0
  1. /* ToiletPapperNumber34 Calcualtor 2014-01-24 v1.0      *
  2.  * file:main.c                                          *
  3.  * Compile:gcc -o ToiletPapperNumber34Calcualtor main.c *
  4.  * gcc(1):http://gcc.gnu.org/releases.html              *
  5.  * gcc(2):http://www.bloodshed.net/download.html        *
  6.  * Credits:w2ch.org-Anon                                */
  7.  
  8. #include <stdio.h> //fprintf()
  9.  
  10. int main(int argc, char **argv)
  11. {
  12.     if(argc!=4)
  13.     {
  14.         fprintf(stderr, "Usage:%s <number in ToiletPapperNumber34 or in decimal with []> <+ or - or / or m(for multiplication as * dose not work for me)> <number in ToiletPapperNumber34 or in decimal with []>\n"
  15.                         "e.g1: %s 1/2 + 1/2 e.g2: %s [3]6 m 1/2", argv[0], argv[0], argv[0]);
  16.         return 0;
  17.     }
  18.    
  19.     int nLigthWorld0 = 0;
  20.     int nDarkWorld0  = 0;
  21.     int nLigthWorld1 = 0;
  22.     int nDarkWorld1  = 0;
  23.     char cOaktree = 0; //used first as temp value for the "2" first values
  24.    
  25.     //get argv[1] value
  26.     if(argv[1][cOaktree] == '[')
  27.     {
  28.          for(++cOaktree; argv[1][cOaktree] != '\0' && argv[1][cOaktree] != ']'; nDarkWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nDarkWorld0 *= 10;
  29.          if(argv[1][cOaktree] == ']')
  30.              for(++cOaktree; argv[1][cOaktree] != '\0'; nLigthWorld0 += (int)(argv[2][cOaktree] & 15), ++cOaktree) nLigthWorld0 *= 10;
  31.          nLigthWorld0 = nLigthWorld0 * nDarkWorld0;
  32.     }
  33.     else
  34.     {
  35.          for(; argv[1][cOaktree] != '\0' && argv[1][cOaktree] != '/'; nLigthWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nLigthWorld0 *= 10;
  36.          if(argv[1][cOaktree] == '/')
  37.              for(++cOaktree; argv[1][cOaktree] != '\0'; nDarkWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nDarkWorld0 *= 10;
  38.          else ++nDarkWorld0;
  39.     }
  40.    
  41.     cOaktree = 0;
  42.     //get argv[3] value
  43.     if(argv[3][cOaktree] == '[')
  44.     {
  45.          for(++cOaktree; argv[3][cOaktree] != '\0' && argv[3][cOaktree] != ']'; nDarkWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nDarkWorld1 *= 10;
  46.          if(argv[3][cOaktree] == ']')
  47.              for(++cOaktree; argv[3][cOaktree] != '\0'; nLigthWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nLigthWorld1 *= 10;
  48.          nLigthWorld1 = nLigthWorld1 * nDarkWorld1;
  49.     }
  50.     else
  51.     {
  52.          for(; argv[3][cOaktree] != '\0' && argv[3][cOaktree] != '/'; nLigthWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nLigthWorld1 *= 10;
  53.          if(argv[3][cOaktree] == '/')
  54.              for(++cOaktree; argv[3][cOaktree] != '\0'; nDarkWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nDarkWorld1 *= 10;
  55.          else ++nDarkWorld1;
  56.     }
  57.    
  58.    
  59.     //get operation from argv[2]
  60.     cOaktree = argv[2][0];
  61.     if(cOaktree != '-' && cOaktree != '+' && cOaktree != 'm' && cOaktree != '/')
  62.     {
  63.          fprintf(stdout, "ERROR:+ or - or / or m(for multiplication as * dose not work for me)");
  64.          return 0;
  65.     }
  66.    
  67.     if((!nLigthWorld0) || (!nLigthWorld1) || (!nDarkWorld0) || (!nDarkWorld1)) fprintf(stdout, "ERROR:One or more of the value you puted in is zero");
  68.    
  69.     //================================================================
  70.     fprintf(stdout, "%d/%d(%.3f) %c %d/%d(%.3f) = ", nLigthWorld0, nDarkWorld0, (float)nLigthWorld0/nDarkWorld0, cOaktree, nLigthWorld1, nDarkWorld1, (float)nLigthWorld1/nDarkWorld1);
  71.     switch(cOaktree)
  72.     {
  73.         case '+':
  74.              nLigthWorld0 += nLigthWorld1;
  75.              nDarkWorld0  += nDarkWorld1;
  76.              break;
  77.         case '-':
  78.              nLigthWorld0 -= nLigthWorld1;
  79.              nDarkWorld0  -= nDarkWorld1;
  80.              break;
  81.         case 'm':
  82.              nLigthWorld0 *= nLigthWorld1;
  83.              nDarkWorld0  *= nDarkWorld1;
  84.              break;
  85.         case '/':
  86.              nLigthWorld0 /= nLigthWorld1;
  87.              nDarkWorld0  /= nDarkWorld1;
  88.              break;
  89.         default:
  90.              break;
  91.     }
  92.     if((!nLigthWorld0) || (!nDarkWorld0)) fprintf(stdout, "ERROR:The result is divided by zero");
  93.     else fprintf(stdout, "%d/%d(%.3f)", nLigthWorld0, nDarkWorld0, (float)nLigthWorld0/nDarkWorld0);
  94.        
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment