How to check the result of division for an integer?
-
Hello everyone, I have two numbers A and B. I need to divide B by A and if the result is an integer then register A and B. Can someone tell me how I can check to see if the result of division is an integer or not? Thank you very much and have a great day. Khoramdin
-
Hello everyone, I have two numbers A and B. I need to divide B by A and if the result is an integer then register A and B. Can someone tell me how I can check to see if the result of division is an integer or not? Thank you very much and have a great day. Khoramdin
What is the datatype of variables "A" and "B"?
int A = 3; int B = 6; int result = B / A;
Did you write like that? if yes, result is INT. :) obviously. or Show us the code that you wrote.Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
What is the datatype of variables "A" and "B"?
int A = 3; int B = 6; int result = B / A;
Did you write like that? if yes, result is INT. :) obviously. or Show us the code that you wrote.Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
Hello Michael, Thanx for the reply, mate. I haven't written any code but what you have written is what I had in mind. The problem is how can I check to see if the result is NOT int. After all, I could have:
int A = 4; int B = 6; double result = B / A;
I simply wish to be able to knowwhen the result is integer and when it is not. Thank you very much and have a great day. Khoramdin -
Hello Michael, Thanx for the reply, mate. I haven't written any code but what you have written is what I had in mind. The problem is how can I check to see if the result is NOT int. After all, I could have:
int A = 4; int B = 6; double result = B / A;
I simply wish to be able to knowwhen the result is integer and when it is not. Thank you very much and have a great day. Khoramdin -
Hello Rocky, Thank you very much, mate. That was EXACTLY what I was looking for. Have a great day. Khoramdin
-
Hello Michael, Thanx for the reply, mate. I haven't written any code but what you have written is what I had in mind. The problem is how can I check to see if the result is NOT int. After all, I could have:
int A = 4; int B = 6; double result = B / A;
I simply wish to be able to knowwhen the result is integer and when it is not. Thank you very much and have a great day. KhoramdinWhile the mod operator solved your problem, it's worth mentioning that B/A will always be an int, unless A is ( or is cast to ) a float or double.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hello Michael, Thanx for the reply, mate. I haven't written any code but what you have written is what I had in mind. The problem is how can I check to see if the result is NOT int. After all, I could have:
int A = 4; int B = 6; double result = B / A;
I simply wish to be able to knowwhen the result is integer and when it is not. Thank you very much and have a great day. Khoramdin -
Hello everyone, I have two numbers A and B. I need to divide B by A and if the result is an integer then register A and B. Can someone tell me how I can check to see if the result of division is an integer or not? Thank you very much and have a great day. Khoramdin