Solved

C++ operating string

Posted on 2000-02-23
7
208 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

706 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

20 Experts available now in Live!

Get 1:1 Help Now