Solved

C++ operating string

Posted on 2000-02-23
7
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

724 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