473,395 Members | 1,791 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,395 software developers and data experts.

rounding to an input value

Hey guys, I'm new to C and programming..so I need some help.
I need a way to round an INPUT number to an INPUT value

so for ex:

enter a decimal: 3.1459
enter the number to round: 3

Answer: 3.146

Here's what I have so far...
#include<stdio.h>
#include<math.h>
int main()
{
float decVal; //DECIMAL VALUE
int round; //# OF PLACES TO ROUND
float a; //ANSWER AFTER ROUNDING

printf("Enter a number as a decimal value (ie. 3.1459): ");
scanf("%f", &decVal);
printf("Enter the number of places to round (ie. 3): ");
scanf("%d", &round);

printf("The number %f rounded to %d decimal places is %f", decVal,
round);
return(0);
}

Sep 4 '06 #1
2 3331
wh***********@gmail.com wrote:
Hey guys, I'm new to C and programming..so I need some help.
I need a way to round an INPUT number to an INPUT value

so for ex:

enter a decimal: 3.1459
enter the number to round: 3

Answer: 3.146

Here's what I have so far...
#include<stdio.h>
#include<math.h>
int main()
{
float decVal; //DECIMAL VALUE
int round; //# OF PLACES TO ROUND
float a; //ANSWER AFTER ROUNDING

printf("Enter a number as a decimal value (ie. 3.1459): ");
scanf("%f", &decVal);
printf("Enter the number of places to round (ie. 3): ");
scanf("%d", &round);

printf("The number %f rounded to %d decimal places is %f", decVal,
round);
You have left out an argument here.
return(0);
}
So you have written the user interface but you have made
no effort with regards to the actual problem. A bit of
a sneaky way to meet the requirement we have around
here that you need to have made an effort before receiving
help.

But anyway , can you solve the problem in case you want
to round decVal to the nearest integer ? Solve this one
first and we'll take it from there.

Sep 4 '06 #2

Spiros Bousbouras wrote:
wh***********@gmail.com wrote:
Hey guys, I'm new to C and programming..so I need some help.
I need a way to round an INPUT number to an INPUT value

so for ex:

enter a decimal: 3.1459
enter the number to round: 3

Answer: 3.146

Here's what I have so far...
#include<stdio.h>
#include<math.h>
int main()
{
float decVal; //DECIMAL VALUE
int round; //# OF PLACES TO ROUND
float a; //ANSWER AFTER ROUNDING

printf("Enter a number as a decimal value (ie. 3.1459): ");
scanf("%f", &decVal);
printf("Enter the number of places to round (ie. 3): ");
scanf("%d", &round);

printf("The number %f rounded to %d decimal places is %f", decVal,
round);

You have left out an argument here.
return(0);
}

So you have written the user interface but you have made
no effort with regards to the actual problem. A bit of
a sneaky way to meet the requirement we have around
here that you need to have made an effort before receiving
help.

But anyway , can you solve the problem in case you want
to round decVal to the nearest integer ? Solve this one
first and we'll take it from there.

#include<stdio.h>
#include<math.h>
int main()
{
int decVal; //DECIMAL VALUE
int round; //# OF PLACES TO ROUND
float a; //ANSWER AFTER ROUNDING
float x;
float y;

printf("Enter a number as a decimal value (ie. 3.1459): ");
scanf("%d", &decVal);
printf("Enter the number of places to round (ie. 3): ");
scanf("%d", &round);

printf("%d",decVal);
printf("The number %d rounded to %d decimal places is %f", decVal,
round);
return(0);
}

Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
4
by: Jackson Peebles | last post by:
Hey everyone! I'm a complete newbie to PHP, and am trying to teach myself how to make some scripts. So far I've done pretty good, but even after searching through all my books, articles, manuals,...
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
2
by: eeyore | last post by:
I've got a problem that seems to be intractable in a purist sense (there are workarounds when you make certain assumptions about the inputs, but no universal solution that I can find). Here's the...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
2
by: bagerbeiger | last post by:
I am relatively new to programming (3-5 months) and have to write a program that prompts users for input (number of items ordered at a restaurant), performs some monetary calculations, and then...
9
by: Verizon News Server | last post by:
Hi, I am a newbie with Javascript. I am trying to build a simple form that calculates the cost of gasoline for a trip. It simply divides the trip distance by the mpg and multiplies that by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.