Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ToiletPapperNumber34 Calcualtor 2014-01-24 v1.0 *
- * file:main.c *
- * Compile:gcc -o ToiletPapperNumber34Calcualtor main.c *
- * gcc(1):http://gcc.gnu.org/releases.html *
- * gcc(2):http://www.bloodshed.net/download.html *
- * Credits:w2ch.org-Anon */
- #include <stdio.h> //fprintf()
- int main(int argc, char **argv)
- {
- if(argc!=4)
- {
- 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"
- "e.g1: %s 1/2 + 1/2 e.g2: %s [3]6 m 1/2", argv[0], argv[0], argv[0]);
- return 0;
- }
- int nLigthWorld0 = 0;
- int nDarkWorld0 = 0;
- int nLigthWorld1 = 0;
- int nDarkWorld1 = 0;
- char cOaktree = 0; //used first as temp value for the "2" first values
- //get argv[1] value
- if(argv[1][cOaktree] == '[')
- {
- for(++cOaktree; argv[1][cOaktree] != '\0' && argv[1][cOaktree] != ']'; nDarkWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nDarkWorld0 *= 10;
- if(argv[1][cOaktree] == ']')
- for(++cOaktree; argv[1][cOaktree] != '\0'; nLigthWorld0 += (int)(argv[2][cOaktree] & 15), ++cOaktree) nLigthWorld0 *= 10;
- nLigthWorld0 = nLigthWorld0 * nDarkWorld0;
- }
- else
- {
- for(; argv[1][cOaktree] != '\0' && argv[1][cOaktree] != '/'; nLigthWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nLigthWorld0 *= 10;
- if(argv[1][cOaktree] == '/')
- for(++cOaktree; argv[1][cOaktree] != '\0'; nDarkWorld0 += (int)(argv[1][cOaktree] & 15), ++cOaktree) nDarkWorld0 *= 10;
- else ++nDarkWorld0;
- }
- cOaktree = 0;
- //get argv[3] value
- if(argv[3][cOaktree] == '[')
- {
- for(++cOaktree; argv[3][cOaktree] != '\0' && argv[3][cOaktree] != ']'; nDarkWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nDarkWorld1 *= 10;
- if(argv[3][cOaktree] == ']')
- for(++cOaktree; argv[3][cOaktree] != '\0'; nLigthWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nLigthWorld1 *= 10;
- nLigthWorld1 = nLigthWorld1 * nDarkWorld1;
- }
- else
- {
- for(; argv[3][cOaktree] != '\0' && argv[3][cOaktree] != '/'; nLigthWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nLigthWorld1 *= 10;
- if(argv[3][cOaktree] == '/')
- for(++cOaktree; argv[3][cOaktree] != '\0'; nDarkWorld1 += (int)(argv[3][cOaktree] & 15), ++cOaktree) nDarkWorld1 *= 10;
- else ++nDarkWorld1;
- }
- //get operation from argv[2]
- cOaktree = argv[2][0];
- if(cOaktree != '-' && cOaktree != '+' && cOaktree != 'm' && cOaktree != '/')
- {
- fprintf(stdout, "ERROR:+ or - or / or m(for multiplication as * dose not work for me)");
- return 0;
- }
- if((!nLigthWorld0) || (!nLigthWorld1) || (!nDarkWorld0) || (!nDarkWorld1)) fprintf(stdout, "ERROR:One or more of the value you puted in is zero");
- //================================================================
- fprintf(stdout, "%d/%d(%.3f) %c %d/%d(%.3f) = ", nLigthWorld0, nDarkWorld0, (float)nLigthWorld0/nDarkWorld0, cOaktree, nLigthWorld1, nDarkWorld1, (float)nLigthWorld1/nDarkWorld1);
- switch(cOaktree)
- {
- case '+':
- nLigthWorld0 += nLigthWorld1;
- nDarkWorld0 += nDarkWorld1;
- break;
- case '-':
- nLigthWorld0 -= nLigthWorld1;
- nDarkWorld0 -= nDarkWorld1;
- break;
- case 'm':
- nLigthWorld0 *= nLigthWorld1;
- nDarkWorld0 *= nDarkWorld1;
- break;
- case '/':
- nLigthWorld0 /= nLigthWorld1;
- nDarkWorld0 /= nDarkWorld1;
- break;
- default:
- break;
- }
- if((!nLigthWorld0) || (!nDarkWorld0)) fprintf(stdout, "ERROR:The result is divided by zero");
- else fprintf(stdout, "%d/%d(%.3f)", nLigthWorld0, nDarkWorld0, (float)nLigthWorld0/nDarkWorld0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment