Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionToolTip Pin
S p k 5215-Jan-10 18:48
S p k 5215-Jan-10 18:48 
AnswerRe: ToolTip Pin
April Fans6-Jan-10 19:16
April Fans6-Jan-10 19:16 
QuestionDefault Button Pin
Pryabu5-Jan-10 17:48
Pryabu5-Jan-10 17:48 
AnswerRe: Default Button Pin
Chris Losinger5-Jan-10 17:52
professionalChris Losinger5-Jan-10 17:52 
GeneralRe: Default Button Pin
Pryabu5-Jan-10 17:58
Pryabu5-Jan-10 17:58 
AnswerRe: Default Button Pin
S p k 5215-Jan-10 18:43
S p k 5215-Jan-10 18:43 
QuestionRe: Default Button Pin
David Crow6-Jan-10 2:52
David Crow6-Jan-10 2:52 
Questiontruncating float Pin
EmbdedCguru5-Jan-10 17:13
EmbdedCguru5-Jan-10 17:13 
HI ,
this is a question purely related to C programming.
I am calculating a division between two float numbers e.g 4.00 / 3.00.
Now if i answer 1.3333 , the functions returns that it is wrong.
i just want to know how to truncate in Float values in C ???

here is the copy of the code:

float d1,d2,d3;


main( )
{

srand(time(0)); // Initialize random number generator.


ans = 1;

while ( ans != 0 )
{

/// starting of For loop ////////////////
wrg =0;

for ( cnt=0;cnt<3;cnt++) {

d1 = float(rand()%x+2 );

d2 = float(rand()%x+2) ;

printf("\n\t Solve this %f / %f :.........\n", d1, d2 );

scanf("%f", &d3);

divid_cheque(d1,d2,d3);



}// ending for loop


printf("\n\t Do you want to continue........\n");
printf("\n\t Type 1 = continue or 0 = to terminate \n");
scanf("\n\t%d", &ans);
}

printf("\n Total number of wrong answers : %d out of %d \n\n", wrg, cnt);

return 0;
}



//////////////////////Division(/) Function defined//////////////////////////////////////////////////////////////////
//unsigned int division( unsigned int y, unsigned int z, unsigned int x )
// unsigned int divid_cheque( unsigned int j, unsigned int k, float l)
// int divid_cheque( float j, float k, float l )
int divid_cheque( float j, float k, float l )
{

float as;

as=j/k;

if ( l== as )

printf("\n \t Right answer..........\n");

if ( l != as ) {

printf(" \n \t << WRONG ANSWER >> \n");

printf("\n \t the right answer is = %f",as);

wrg++ ; // incrementing counter for wrong answers
}
else

return (wrg);
}
////////////////////////////////////////////////////////////////////////////////////////////////
AnswerRe: truncating float Pin
Tim Craig5-Jan-10 17:41
Tim Craig5-Jan-10 17:41 
AnswerRe: truncating float Pin
Chris Losinger5-Jan-10 17:54
professionalChris Losinger5-Jan-10 17:54 
AnswerRe: truncating float Pin
«_Superman_»5-Jan-10 19:16
professional«_Superman_»5-Jan-10 19:16 
AnswerRe: truncating float Pin
beko5-Jan-10 19:49
beko5-Jan-10 19:49 
QuestionUsing Managed Code in C++ Pin
Expert Coming5-Jan-10 9:35
Expert Coming5-Jan-10 9:35 
AnswerRe: Using Managed Code in C++ Pin
CPallini5-Jan-10 11:46
mveCPallini5-Jan-10 11:46 
AnswerRe: Using Managed Code in C++ Pin
«_Superman_»5-Jan-10 15:56
professional«_Superman_»5-Jan-10 15:56 
QuestionSleep less than 1 ms Pin
Adnan Merter5-Jan-10 8:50
Adnan Merter5-Jan-10 8:50 
AnswerRe: Sleep less than 1 ms Pin
Nemanja Trifunovic5-Jan-10 9:14
Nemanja Trifunovic5-Jan-10 9:14 
AnswerRe: Sleep less than 1 ms Pin
Cedric Moonen5-Jan-10 9:15
Cedric Moonen5-Jan-10 9:15 
GeneralRe: Sleep less than 1 ms Pin
Adnan Merter5-Jan-10 9:17
Adnan Merter5-Jan-10 9:17 
GeneralRe: Sleep less than 1 ms Pin
Cedric Moonen5-Jan-10 9:20
Cedric Moonen5-Jan-10 9:20 
GeneralRe: Sleep less than 1 ms Pin
Adnan Merter5-Jan-10 9:21
Adnan Merter5-Jan-10 9:21 
AnswerRe: Sleep less than 1 ms Pin
CPallini5-Jan-10 11:25
mveCPallini5-Jan-10 11:25 
GeneralRe: Sleep less than 1 ms Pin
Adnan Merter6-Jan-10 4:05
Adnan Merter6-Jan-10 4:05 
GeneralRe: Sleep less than 1 ms Pin
CPallini6-Jan-10 5:08
mveCPallini6-Jan-10 5:08 
AnswerRe: Sleep less than 1 ms Pin
Luc Pattyn5-Jan-10 15:32
sitebuilderLuc Pattyn5-Jan-10 15:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.