| | |
Calc in C
Hi everyone,
I've been working on this calculator for days, and now i am making it opensource so that everyone can bring his own contribution, please comment all your codes very well.
I've been working on this calculator for days, and now i am making it opensource so that everyone can bring his own contribution, please comment all your codes very well.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char **argv) { double a, b; char buf[25]; if ( argc > 3 ) { if ( sscanf(argv[1], "%lf", &a) == 1 && sscanf(argv[3], "%lf", &b) == 1 ) { switch ( argv[2][0] ) { case '+': printf("%g PLUS %g = %g\n", a, b, a + b); char first[60]; char second[60]; char result[60]; itoa(a, first, 10); itoa(b, second, 10); itoa(a+b, result, 10); FILE *cpy; cpy = fopen("c:\\calc.txt", "a"); fprintf(cpy, first); fprintf(cpy, " PLUS "); fprintf(cpy, second); fprintf(cpy, " = "); fprintf(cpy, result); fprintf(cpy, " @ "); fprintf(cpy, strdate(buf)); fprintf(cpy, " & "); fprintf(cpy, strtime(buf)); fprintf(cpy, "\n"); break; case '-': printf("%g MINUS %g = %g\n", a, b, a - b); char firstm[60]; char secondm[60]; char resultm[60]; itoa(a, firstm, 10); itoa(b, secondm, 10); itoa(a-b, resultm, 10); FILE *cpym; cpy = fopen("c:\\calc.txt", "a"); fprintf(cpy, firstm); fprintf(cpy, " MINUS "); fprintf(cpy, secondm); fprintf(cpy, " = "); fprintf(cpy, resultm); fprintf(cpy, " @ "); fprintf(cpy, strdate(buf)); fprintf(cpy, " & "); fprintf(cpy, strtime(buf)); fprintf(cpy, "\n"); break; case '*': printf("%g MULTIPLY BY %g = %g\n", a, b, a * b); char firstmu[60]; char secondmu[60]; char resultmu[60]; itoa(a, firstmu, 10); itoa(b, secondmu, 10); itoa(a*b, resultmu, 10); FILE *cpymu; cpy = fopen("c:\\calc.txt", "a"); fprintf(cpy, firstmu); fprintf(cpy, " MULTIPLY "); fprintf(cpy, secondmu); fprintf(cpy, " = "); fprintf(cpy, resultmu); fprintf(cpy, " @ "); fprintf(cpy, strdate(buf)); fprintf(cpy, " & "); fprintf(cpy, strtime(buf)); fprintf(cpy, "\n"); break; case '/': printf("%g DIVIDE BY %g = %g\n", a, b, a / b); char firstd[60]; char secondd[60]; char resultd[60]; itoa(a, firstd, 10); itoa(b, secondd, 10); itoa(a/b, resultd, 10); FILE *cpyd; cpy = fopen("c:\\calc.txt", "a"); fprintf(cpy, firstd); fprintf(cpy, " DIVIDE "); fprintf(cpy, secondd); fprintf(cpy, " = "); fprintf(cpy, resultd); fprintf(cpy, " @ "); fprintf(cpy, strdate(buf)); fprintf(cpy, " & "); fprintf(cpy, strtime(buf)); fprintf(cpy, "\n"); break; default: puts("Error"); break; } } } return 0; }
Similar Threads
Other Threads in the C Forum
- JS Grade Calc (JavaScript / DHTML / AJAX)
- Calc Problem (C++)
- Calc end and loop? (C++)
- Need help,my C++ calc (C++)
- Need help with a program that calc Tax (C++)
Other Threads in the C Forum
- Previous Thread: Story Builder
- Next Thread: Windows Log-off
| Thread Tools | Search this Thread |
Tag cloud for C
2darray api array arrays behaviour binary binarysearch c++ char character code coke command conversion convert copyimagefile creafecopyofanytypeoffileinc database decimal directory dude dynamic error exec factorial fgets file fork forloop function functions givemetehcodez grade graphics help.forensic homework i/o input insert int integer lazy library line linked linkedlist linux list lists locate logical_drives loop loopinsideloop. malloc matrix memory motherboard mysql newbie no-effort opensource operator output path pointer pointers printf problem process program programming read recursion recursive recv reverse roman scanf scripting sms_speak socketprograming spoonfeeding stdout steganography string strings strtok structures student suggestions syntax system systemcall turbo-c turboc unix user variable windows words



