473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

plz help with a rounding program..

29
the question that i have to solve says:
fuction floor can be used to round a number to a specific decimal place. the statement y=floor(x*10+0.5)/10; rounds x to the tenths position. write a program that defines four functions to round a number x in various ways:
1- roundToInteger(number)
2- roundToTenths(number)
3-roundToHundredths(number)
4- roundToThousandths(number)
for each value read, your program should print the original value, the number rounded to nearest tenths,hundredths,thousandths.
this is what i have tried to write..but ofcourse..and like usual..lol..i have lots of mistakes..i would really appreciate the help
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

# include<cmath>

//declaration of functions
void roundToInteger(double);
void roundToTenths(double);
void roundToHundredths(double);
void roundToThousandths(double);

int main()
{
unsigned short choice;
do
{
float x;
cout<<”-1- round decimal to the nearest integer”<<endl;
cout<<”-2- round decimal to the nearest tenth”<<endl;
cout<<”-3- round decimal to the nearest hundredth”<<endl;
cout<<”-4- round decimal to the nearest thousandth”<<endl;
cout<<”please enter a decimal”<<endl;
cin>>x;
cout <<"You chose Menu Option #"<<choice<<endl ;
}
while(selection<1 || selection>4);

switch(choice)
{
case 1 :
roundToInteger(number);
break ;
case 2 :
roundToTenths(number);
break;
case 3 :
roundToHundredths(number);
break;
case 4:
roundToThousandths(number);
break;
default:
cout<<”you should never get here\a\a\a\a!!!”;
}
}while(choice != 5);
cout<<”you choose to quit\a\a\a"<<endl;
return 0;
}

//definition of functions
void roundToInteger(double number)
{
y= floor(x+0.5);
cout<<”the decimal ”<<x<<” rounded to the nearest integer = “<<number<<endl;
}
void roundToTenths( double number)
{
y=floor(x*10+0.5)/10;
cout<<”the decimal ”<<x<<” rounded to the nearest tenths = “<<number<<endl;
}
void roundToHundredths(double number)
{
y=floor(x*100+0.5)/100;
cout<<”the decimal ”<<x<<” rounded to the nearest hundredths = “<<number<<endl;
}
void roundToThousandths(double number)
{
y=floor(x*1000+0.5)/1000;
cout<<”the decimal ”<<x<<” rounded to the nearest thousandths = “<<number<<endl;
}
Jan 17 '07 #1
0 1608

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: towers | last post by:
Hello, I've got a bit of experience in C++, but I'm writing my first app that is dependent on relatively precise math functions. The app requires that I get a time stamp based on s sample...
4
by: Kelly Mah | last post by:
Sorry if I got the wrong group. I seem to be running into a rounding issue on a Linux AS2.1 box using gcc 2.95. This program always returns 419 on Linux, but on a Solaris machine, I get the...
3
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
5
by: Jason | last post by:
I am having a rounding problem in a value i am trying to display in VB.NET. If I have the following code: Dim x As Single = 2726.795 Dim y As Single = Math.Round(2726.795, 2) Dim s as String =...
14
by: ray | last post by:
Dear all, In my vb.net program, I have to round a decimal number to two decimal place. For example, for the expression "Decimal.Round(31* 1.555, 2)", I should get the result "48.21". However, the...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.