The code actually works, but I would like to know what in this program would be considered "bad" programming. This code converts decimals to fracts. It also is not object-oriented.
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
char decimal[21], numerator_string[21];
int gcf, reduced_numerator, reduced_denominator;
long length, denominator, numerator;
cout << "Enter decimal: ";
cin.get(decimal, 21);
cin.ignore(80, '\n');
length = strlen(decimal);
// omit the "." to get the numerator
for(int i = 0; i <= length; i++)
{
numerator_string[i] = decimal[i+1];
}
length = strlen(numerator_string);
denominator = pow10l(length);
numerator = atol(numerator_string);
for(int x = 1; x <= numerator; x++)
{
if((numerator % x == 0) && (denominator % x == 0))
{
gcf = x;
}
}
if (gcf == 1)
{
cout << "Can't be turned to a fraction" << endl;
getch();
return 0;
}
reduced_numerator = numerator / gcf;
reduced_denominator = denominator / gcf;
cout << "\n" << reduced_numerator << "\\"
<< reduced_denominator << endl;
getch();
return 0;
}