?
Solved

C++ operating string

Posted on 2000-02-23
7
Medium Priority
?
252 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 150 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.
Suggested Courses

764 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