# Round Numbers

Page 1 of 1

## 4 Replies - 1360 Views - Last Post: 24 January 2010 - 10:04 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=151780&amp;s=866d7e3253953c702b6d3b872920aeb9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 vplazed

Reputation: 0
• Posts: 23
• Joined: 28-September 09

# Round Numbers

Posted 24 January 2010 - 03:52 PM

Hi, I am having some difficulty with rounding numbers. I not getting output of rounding. Also, I have some difficulty on rounding negative numbers. for example 3.4=3 3.5=4 -1.5=-1 -2.4=2. The output i am getting is 3.4...

```#include <iostream.h>
#include <math.h>
int main()
{
double number;
int place;
cout<<"Enter a number"<<endl;
cin>>number;
number *= 10^place;
int istack = (int)floor(number);
int out = number-istack;
if (out < 0.5){
floor(number);
number /= 10^place;
cout<<number<<endl;
return number;
}
if (out > 0.4) {
ceil(number);
number /= 10^place;
cout<<number;
return number;
}
}
```

Is This A Good Question/Topic? 0

## Replies To: Round Numbers

### #2 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Round Numbers

Posted 24 January 2010 - 04:04 PM

1st Your main function is an int but trying to return a double.
2nd You didn't include objects. For example a lot of people use 'using namespace std;'

This post has been edited by seeP+: 24 January 2010 - 04:06 PM

### #3 nmeans73

Reputation: 19
• Posts: 59
• Joined: 26-December 09

## Re: Round Numbers

Posted 24 January 2010 - 09:00 PM

not sure if this changes anything but, unless you are using a very old compiler, your two includes at the top are incorrect. They should be:
```#include <iostream>

//and

#include <cmath>

```

### #4 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: Round Numbers

Posted 24 January 2010 - 09:02 PM

Why are you trying to return values out of main???

example round funciton
```#include <iostream>
#include <cmath>

using namespace std; //<---neeed this

int round(double out)
{
if (out<0)
out-=0.5;
else
out+=0.5;
return (int)out;

}
int main()
{
double number;
cout<<"ENTER A NUMBER : ";
cin>>number;

cout<<round(number)<<endl;

cin.ignore();
cin.get();

return 0;
}

```

This post has been edited by ImaSexy: 24 January 2010 - 09:07 PM

### #5 [email protected]

Reputation: 1
• Posts: 57
• Joined: 06-February 08

## Re: Round Numbers

Posted 24 January 2010 - 10:04 PM

int function doesnt return a duoble type
include 'using namespace std;' in begining