This is the whole thing:
Code:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
#include <cmath>
void seperate (double numbertobesplit); // function one //
void printOut (double wholepart, double fractional, int numbersign); // function two //
int main()
{
double UsersNumber;
cout << "Enter a value to analyse:";
cin >> UsersNumber;
seperate (UsersNumber);
return 0;
}
void seperate (double numbertobesplit) // the first function //
{
double wholepart, fractional;
int numberssign;
wholepart = floor (numbertobesplit);
fractional = fabs (numbertobesplit) - wholepart;
if (wholepart > 0){
numberssign = 1;}
else{
numberssign = 0;}
printout (wholepart, fractional, numberssign); // this is the call to the second function //
}
void printOut (double wholepart, double fractional, int numberssign) // second function starts here //
{
cout << "sign: ";
if (numberssign = 1){
cout << "+\n";}
else{
cout << "-\n";}
cout << "Whole number magnitude: " << wholepart << endl;
cout << "Fractional part: " << fractional << endl;
}
If you are wondering its supposed to split a floating point number into three pieces, one part is the sign, the next is the magnitude followed by the fractional part.