Solved

C++ operating string

Posted on 2000-02-23
7
219 Views
Last Modified: 2010-04-02
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
0
Comment
Question by:wolv491
7 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2550230
Don't understand:
int i, j, r;
r = i % j;
0
 
LVL 1

Expert Comment

by:Binder
ID: 2550232
 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.
0
 

Author Comment

by:wolv491
ID: 2550254
Edited text of question.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:arnond
ID: 2550305
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2550361
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>
0
 
LVL 22

Expert Comment

by:nietod
ID: 2550382
>> 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
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 2552625
Is it just me, or does the question title have nothing to do with the question.

And the question itself doesn't make sense.

>I'm going crazy trying to get my
>remainders to display

But your variable is called 'quotient' and you want remainders .. no wonder you're going crazy

>I'M using the right operators but its
>still coming back a whole number.

That is because quotients and remainders ARE whole numbers

>How do I get correct Quotient
>responce.

Which is it .. quotient or remainder?

> Quotient=Int_1%int_2;
> 5%2 does not =2 it equals 2 etc/etc

its not 2 .. it is two .. what does that mean?

All I can thing of is that you REALLY want to divide 5 by 2 and get 2.5 OR you want to get .5

Here's how
int i,j,k;
double d,r;
i = 5;
j = 2;
d = i/(double)j; // d is now 2.5
r = (i%j)/double(j) // r is now .5

OK?




0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now