I'm crazy about minimizing the size of my programs and using the most minimial amount of code! I've finished a homework assignment, works perfectly, now I just want to minimize the code and make it smaller.
Yes... I may go ahead and remove the functions, I had split the code up in anticipation of converting any given base to decimal being added to it, but it is no longer the case.Code:#include <iostream.h> void decimaltobase(int a[], double decimal, int whole, double fraction, int type); void dectobasemenu(int a[], double decimal); main() { int a[100]; double decimal; dectobasemenu(a, decimal); return 0; } void decimaltobase(int a[], double decimal, int whole, double fraction, int type) { int legnth1 = 0, temp = 0; //for the whole value for (int i = 0; whole > 0; i++) { a[i] = whole % type; whole = whole / type; legnth1++; } //for (int i= 0; fracion > 0; i++) cout << decimal << " represented in base-"<<type<<" is "; for (int i = legnth1 -1; i >=0; i--) { if ((type > 10)&&( a[i]> 9)) { char c = 'a'; for (int j = 10; j < a[i]; j++) { c++; } cout << c; } else { cout << a[i]; } } if (fraction > 0) cout << "."; for (int i = 0; fraction != 0; i++) { fraction = fraction * type; temp = int(fraction); if ((type > 10) && (temp > 9)) { char c = 'a'; for (int i = 10; i < temp; i++) { c++; } cout << c; } else { cout << temp; } fraction = fraction - double(temp); } cout << endl << endl; } void dectobasemenu(int a[], double decimal) { int type = 1; do { cout << "Enter the number system base (2--36) (press 0 to quit): "; cin >> type; if ((type < 2)&&(type != 0)) { cout << "That is not a valid base!"<<endl; dectobasemenu(a, decimal); } if (type == 0) break; do { cout << "Enter a decimal integer to convert to base-" <<type<<": "; cin >> decimal; int whole = int(decimal); double frac = decimal - double(whole); if (decimal == 0) break; decimaltobase(a ,decimal, whole, frac, type); }while(decimal != 0); }while (type !=0); }
Please suggest any ideas on how I can minimize the amount of code I could use or any other improvements, but PLEASE do not reply to the post with code... pseudeo code is ok, but I'd mainly just like suggestions.



LinkBack URL
About LinkBacks


