wolv491
asked on
C++ operating string
I'm going crazy trying to get my remainders to display I'M using the right operators but its still coming back a whole number.
How do I get correct Quotient responce.
Quotient=Int_1%int_2;
5%2 does not =2 it equals 2 etc/etc
How do I get correct Quotient responce.
Quotient=Int_1%int_2;
5%2 does not =2 it equals 2 etc/etc
I don´t know if I understand you correctly but are you trying to
do some divisions out of a string? A bit of code of what you are doing
may help.
do some divisions out of a string? A bit of code of what you are doing
may help.
ASKER
Edited text of question.
if you want real decimal numbers (like 1.23456...) you need to use floats. Either use floats instead of ints or cast them.
float fl_i,fl_j,q;
int int_i,int_j;
q=fl_i%fl_j;
or
q=((float) (int_i))/((float)(int_j));
Hope that's what you want,
Arnon David.
float fl_i,fl_j,q;
int int_i,int_j;
q=fl_i%fl_j;
or
q=((float) (int_i))/((float)(int_j));
Hope that's what you want,
Arnon David.
wolv491, please do not edit the question once a dialog has started, it makes it impossible to follow.
>> 5%2 does not =2 it equals 2 etc/etc
It should equal 1
We need to know what it is you are doing. Can you explain this a little more clearly and/or post some code>
>> 5%2 does not =2 it equals 2 etc/etc
It should equal 1
We need to know what it is you are doing. Can you explain this a little more clearly and/or post some code>
>> correct Quotient responce.
>> Quotient=Int_1%int_2;
pehaps you are mixing up / and %.
/ does division and returns the quotient. when deailing with ints, it returns only the integer portion fo the quotient, like
5/2 = 2
6/2 = 3
7/2 = 3
8/2 = 4
% does division and returns the remainder. like
5%2 = 1
6%2 = 0
7%2 = 1
5%3 = 2
6%3 = 0
7%3 = 1
8%3 = 2
9%3 = 0
>> Quotient=Int_1%int_2;
pehaps you are mixing up / and %.
/ does division and returns the quotient. when deailing with ints, it returns only the integer portion fo the quotient, like
5/2 = 2
6/2 = 3
7/2 = 3
8/2 = 4
% does division and returns the remainder. like
5%2 = 1
6%2 = 0
7%2 = 1
5%3 = 2
6%3 = 0
7%3 = 1
8%3 = 2
9%3 = 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int i, j, r;
r = i % j;