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;
             } 
        }
     }
}

the program will take the values and store it in reduced rational form then apply all the artimatic operators on it and display the values in rational and decimal form

**Please use code-tags in the future**

The following expression numerater/denominater is a division of integers, this will be computed with integer arithmetics (the remainder of the division is discarded, i.e. 1 / 2 = 0, 4 / 3 = 1, etc.).

To obtain the answer of the division as a "normal" real-valued division, you need to cast the integers to floating-point values first, and then do the division, i.e. float(numerater) / float(denominater) .

That should fix your problem.

>> how do u use it

How do you use what? Don't make us play 20 questions. If you have a question about Mike's answer, state the question. We don't know what "it" refers to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.