View Single Post
Old Jan 28th, 2005, 10:30 AM   #5
Border Fox
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 Border Fox is on a distinguished road
Quote:
Originally Posted by Benoit
What errors does the complier give you after correcting the ones he pointed out?
[d4033875@linux12 ~]$ gcpp ica3.cpp
[d4033875@linux12 ~]$ ica3
Input a real number (one with decimal point):
34.56
Number to be analysed: 34.56
Sign: �
Whole number: 134515518
Fractional part: 1.06444e-304

iv tried debugging methods:

void separate ( struct number value )
{
if ( value.initial > 0 )
value.sign = '+';
else
value.sign = '-';

value.mag = floor ( value.initial );
value.fract = fabs ( value.initial - value.mag );

cout << "In function separate(): " << endl;
cout << "Number to be analysed: " << value.initial << endl;
cout << "Sign: " << value.sign << endl;
cout << "Whole number: " << value.mag << endl;
cout << "Fractional part: " << value.fract << endl << endl;

}

and also

cout << "Input a real number (one with decimal point): " << endl;
cin >> value.initial;

separate ( value );

cout << "After function separate(): " << endl;
cout << "Number to be analysed: " << value.initial << endl;
cout << "Sign: " << value.sign << endl;
cout << "Whole number: " << value.mag << endl;
cout << "Fractional part: " << value.fract << endl << endl;


printOut ( value );


this enabled me to see that the problem lies in main ( i think )
when i did the debuggin in function separate the program successfully compiled error-free, it printed the correct results...BUT it also printed a second set of incorrect results after the correct set. see below:

[d4033875@linux12 ~]$ gcpp ica3.cpp
[d4033875@linux12 ~]$ ica3
Input a real number (one with decimal point):
23.45
In function separate():
Number to be analysed: 23.45
Sign: +
Whole number: 23
Fractional part: 0.45

Number to be analysed: 23.45
Sign: �
Whole number: 134515794
Fractional part: 1.06444e-304


from this i think that function separate is fine.
but the values arent being passed back to main....OR ELSE the values aren't being passed from main to printOut....OR ELSE there is something wrong with printOut.


question is.,...what? and how do i fix it? HELP!!
Border Fox is offline   Reply With Quote