# tough question

• 10-25-2002
CBeginner
tough question
Write a program that uses a user defined function called 'truncate()' which separates the integer and the decimal part from a float value.

The prototype for this function is as follows :

void truncate (float);

The function accepts a float value from main () and truncates the decimal part of the variable

plz help
• 10-25-2002
Hammer
Read this, in particular, the homework section.
• 10-25-2002
Prelude
Please don't just post your homework questions, at least try to solve them and be able to prove it or you won't get help here. I will offer suggestions to get you started though, try printing the float value cast to an int and see what you get.

-Prelude
• 10-25-2002
CBeginner
i tried. it was wrong, which is why i am here. so what, the rules are i cant be helped?
• 10-25-2002
CBeginner
my output:

Enter a decimal point number : 12.60

After truncating the variable, the values are : 12.00 and 0.75

Do you want to run the operation again [Y/N]? n

Press any key to continue

------------

wrong.
• 10-25-2002
Prelude
>i tried. it was wrong, which is why i am here.
Then you'll need to describe what the output should look like in all cases because this works just peachy for me and I can't see you needing to handle values that would overflow an int for homework:
Code:

```void truncate ( float val ) {   std::cout<< (int)val <<std::endl; }```
>so what, the rules are i cant be helped?
No, the rules are that you will not be helped if you don't bother trying to solve the problem on your own. We assume this to be the case if you do nothing but post the problem you were given and not any solutions you have tried that didn't work.

-Prelude
• 10-25-2002
CBeginner
check it out.

//
//
//

#include <iostream.h>

void truncate (float);

void main ()

{

int a;
int b;
float c;

cin>>c;

cout<<"values are "<<a<<"and"<<b<<"<<endl;

}

void truncate (float)

{

int a= float c;
int b=(c-a);

return a,b;

}
• 10-25-2002
salvelinus
Well, for one thing, where in main do you call truncate()?
For another, how are you returning two values?
For that matter, why does truncate() have a data type but not a data variable? etc...
I'm not trying to pick on you, but you need to spend some time learning about functions and passing arguments; forget about actually splitting the integer and decimal parts for now.