guys i made a program and it is working the prob is that it is not displaying the values to in float so guys plz help me in this regard
#include "stdafx.h"
#include<iostream>
#include <stdio.h>
using namespace std ;
void reduce(int&,int&);
class decimal
{
int numerater;
int denominater;
public :
decimal():numerater(0),denominater(0)
{
}
decimal(int a,int b):numerater(a),denominater(b)
{
//cout<<numerater<<endl<<denominater<<endl;
}
void add(decimal,decimal);
void multi(decimal,decimal);
void divide(decimal,decimal);
void subtract(decimal,decimal);
void show_add ()
{float x=numerater/denominater;
cout<<"ans of addition of two ratinal function is "<< numerater<<"/"<<denominater<<endl<<"or"<<x<<endl ; }
void show_multi ()
{float y=numerater/denominater;
cout<<"ans of multi of two ratinal function is "<<numerater<<"/"<<denominater<<endl<<"or"<< y<<endl ; }
void show_divide ()
{float z=numerater/denominater;
cout<<"ans of divide of two ratinal function is "<< numerater<<"/"<<denominater<<endl<<"or"<<z<<endl ; }
void show_subtract()
{float m=numerater/denominater;
cout<<"ans of subraction of two ratinal function is "<< numerater<<"/"<<denominater<<endl<<"or"<<m<<endl ; }
};
void decimal::add(decimal d1,decimal d2)
{denominater=(d1.denominater*d2.denominater);
numerater=(d1.denominater*d2.numerater)+(d2.denominater*d1.numerater);
reduce(denominater,numerater);
show_add ();
}
void decimal::multi(decimal d1,decimal d2)
{denominater=(d1.denominater*d2.denominater);
numerater=(d1.numerater*d2.numerater);
reduce(denominater,numerater);
show_multi();}
void decimal::divide(decimal d1,decimal d2)
{denominater=(d1.denominater*d2.numerater);
numerater=(d1.denominater*d2.numerater);
reduce(denominater,numerater);
show_divide ();}
void decimal::subtract(decimal d1,decimal d2)
{denominater=(d1.denominater*d2.denominater);
numerater=(d1.denominater*d2.numerater)-(d2.denominater*d1.numerater);
reduce(denominater,numerater);
show_subtract ();
}
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,d;
cout<<"enter the value apart from zero\n";
cin>>a>>b;
cout<<"enter the value of other rational no \n";
cin>>c>>d;
reduce(a,b);reduce(c,d);
decimal d1(a,b),d2(c,d),d3;
d3.add(d1,d2);
d3.subtract(d1,d2);
d3.multi(d1,d2);
system("pause");
}
void reduce(int &a,int &b)
{
for(int i=1;i<=20;i++)
{
for(int j=1;j<=100;j++)
{
if(a%j == 0 && b%j == 0)
{
a=a/j;
b=b/j;
}
}
}
}