954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

calling a decimal function

Ok, so i changed the "/" to a '/' but i can't get my calculate decimal function for work. I want to call a private function calculateDecimalValue() that computes a floating decimal of the fraction inside the enterFractionValue() function after the num and den are filled. I'm not understanding how to get it inside the enterFractionValue() function. I got the slash to work but the decimal in displayDecimal is just junk. Thanks again, Here's the code i have:

class Fraction
{
private:
double num, den;
double decimal;
static char slash;

void calculateDecimalValue(float decimal);

public:
void enterFractionValue();
void displayFraction();
static void displaySlash();

};
//implementation part-to be named-fraction.cpp
char Fraction::slash='/';

void Fraction::displaySlash()
{
cout<>num;
cin.ignore(80,'\n');
cout <<"The numerator is "<>den;
cin.ignore(80,'\n');

while (den == 0)
{
cout<<"Enter a number greater than zero."<>den;
cin.ignore(80,'\n');
}
cout <<"The denominator is "<>input;
cin.ignore(80,'\n');
while (input != 1 && input !=2)
{
cout<<"Your entry must be a 1 or a 2, please try again."<>input;
cin.ignore(80,'\n');
}
if (input == 1)

cout<<"The fraction in traditional form is "<
#include "fraction.h"
#include "fraction.cpp"
int main()
{
Fraction oneFraction;
oneFraction.enterFractionValue();
oneFraction.displayFraction();

cout << "Press Enter to continue";
getchar();
return 0;
}

Guppy25
Newbie Poster
4 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

You don't need a private function here. Also I don't think it's a good idea to make the numerator and denominator doubles. For one thing, they may not print out properly, i.e., you may have a fraction 3.0/4.0 where you really want 3/4.

Attached is a simple fraction program. (It really should be improved by reducing to lowest terms.)

murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1
 

Ok, so i changed the "/" to a '/' but i can't get my calculate decimal function for work. I want to call a private function calculateDecimalValue() that computes a floating decimal of the fraction inside the enterFractionValue() function after the num and den are filled. I'm not understanding how to get it inside the enterFractionValue() function. I got the slash to work but the decimal in displayDecimal is just junk. Thanks again, Here's the code i have:

class Fraction { private: double num, den; double decimal; static char slash; void calculateDecimalValue(float decimal);

public: void enterFractionValue(); void displayFraction(); static void displaySlash(); }; //implementation part-to be named-fraction.cpp char Fraction::slash='/'; void Fraction::displaySlash() { cout<>num; cin.ignore(80,'\n'); cout <<"The numerator is "<>den; cin.ignore(80,'\n');

while (den == 0) { cout<<"Enter a number greater than zero."<>den; cin.ignore(80,'\n'); } cout <<"The denominator is "<>input; cin.ignore(80,'\n'); while (input != 1 && input !=2) { cout<<"Your entry must be a 1 or a 2, please try again."<>input; cin.ignore(80,'\n'); } if (input == 1)

cout<<"The fraction in traditional form is "< #include "fraction.h" #include "fraction.cpp" int main() { Fraction oneFraction; oneFraction.enterFractionValue(); oneFraction.displayFraction(); cout << "Press Enter to continue"; getchar(); return 0; }

You don't need a private function.. Here's a simple fraction class. I hope this works. The last time I tried attaching a file I didn't succeed.)

Attachments fraction.cpp (0.7KB)
murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You