C++ :: Rounding Numbers To Hundreds?

Jul 18, 2013

I have made a random number generator to create a number between 1000 and 9000, but I always get numbers with many 10s and units. I want to round them 100s.

Is there any way to do this?

View 4 Replies


ADVERTISEMENT

C :: Rounding Of Numbers Using Int Identifier

Apr 23, 2013

I have an assignment for uni which requires the program to ask the user to input a number in for a variable to use in later equations. The assignment specifies that if the number that is input into the program is not an interger that it needs to be rounded UP to the nearest interger. e.g. 2.5 = 3, 5.00001 = 6 etc. i have identified this variable using "int" which i know makes it an interger however it also always rounds the number DOWN to the nearest interger. I was just wondering what the best way to approach this problem was. The only idea i have is to put + 0.99999 at the end of this variable when it is worked out so that if it is not a whole number it will be raised above the next interger and then rounded down however this will not work if there is too many decimal places.

View 6 Replies View Related

C :: How To Use Rounding Function

Jan 16, 2014

I want to round to the 2nd digit in a float. Such as 1.85458 to 1.85. How would i go about doing this. I currently keep rounding to the closest integer so the above would round to 2.

Code:
#include <stdio.h>
#include <math.h>
int main(void){
float n;

[Code] ....

View 4 Replies View Related

C :: Rounding Function Not Working

Oct 12, 2013

Why the roundf function is not successfully rounding my numbers.

Code:
#include <stdio.h>
#include <math.h>
//function declarations
void CelToFah (int ctemp, int ftemp);

[Code]....

it produces a correct number when called, but it is not a rounded number, the roundf((float)cel) does nothing. I get the same number with and without it.

View 6 Replies View Related

C :: Rounding To The Nearest Cent?

Feb 4, 2014

I'm having trouble with rounding to the nearest cent in this program. It's the only thing that i need. The result i need is just off by one cent. I tried multiplying the interest amount by 100 and adding .5 then dividing all that by 100 but that just made it worse. Here's the code:

Code:
#include <stdio.h>
int main()
{
int count=0;

[Code]....

View 6 Replies View Related

C++ :: Rounding To Nearest Half?

Mar 9, 2014

How do I round to the nearest half integer?

Example;
0 to 0.2 = 0
0.3 to 0.5 = 0.5
0.6-0.9 = 1

What's the formula for C++?

I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?

For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2.
8.4 * 2 = 16.8
16.8 + .5 = 17.3
17.3 - decimal = 17
17/2 = 8.5

I want to do something like;

cout << " Half number: << (x*2+.5)remove decimal/2 << endl;

What would I have to put in place of "remove decimal"?

View 4 Replies View Related

C++ :: Rounding And Converting To Integer?

Oct 4, 2014

Ok so I'm in a programming 1 class working with c++. I have the following assignment:

Write a C++ program that:
asks for and accepts the Percentage earned with as a double (i.e. 75.45)
rounds it to an integer (>= .5 rounds up, <.5 rounds down.)
prints the original Percentage and the corresponding Grade and Points exactly as shown below.
prints an error message for any input that is less than 0 or greater than 100.

For example, if user enters 89.4, the program prints out:
Percentage: 89.4% Grade: B Points: 3.00
You must use an if-else statement to do this in your program.
Use fixed and precision output manipulators (see Ch. 3) to display the values with the exact precision shown above.

IMPORTANT:
Each if statement condition should contain only one comparison! read this again
This means code that is similar to this is NOT okay:  if (Percentage >= 80.00 && Percentage <90.00)
This code is not acceptable because the if statement condition above has two comparisons.
(Hint: If you order your if-else chain statements correctly, you will only need one comparison in each.)

I have the program working, but I'm pretty sure I'm not rounding how my professor would like it to. This is my code:

#include <iostream>
#include <cmath>
#include <iomanip>

[Code].....

So my issue here is the rounding, and then theres the converting the double percetnage to an integer. In my next assignment I have to write the program with a switch statement.

View 3 Replies View Related

C Sharp :: Rounding Up To Nearest 100

Jul 28, 2012

Rounding a numerical figure up to the nearest hundred. E.G.:

256 >> 300
654 >> 700
15 >> 100

I would like to know the formula to enter into Visual Basic 2008. I'm making a calculator Program, and i need a function that rounds up to the nearest 100...

View 5 Replies View Related

C++ :: Dice Simulator - Floats Rounding Up

Oct 28, 2013

I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).

Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.

View 5 Replies View Related

Visual C++ :: Rounding A Number Multiple Of Another

Jul 23, 2013

How would I be able to round a number in multiples of another...

Let's say width is 150
And multiple to be 64...
I want 150 to become 128...
if it was 160 to become 192...

The width number will change and I want to covert it in multiples of the other number example 64... The minimum value will always be the multiple number used...

View 7 Replies View Related

C++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C :: Finding Written Numbers In A String And Converting Them To Decimal Numbers

Jun 20, 2013

User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.

I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.

Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;

[Code] .....

View 7 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.

I'm stuck on how to put the prime numbers into an array.

The input file has the numbers 1 & 100.

Here's what I have so far.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");

[Code] .....

View 1 Replies View Related

C :: Find Duplicate Numbers And Numbers Found Once In Array

Dec 7, 2013

Question: How to find a duplicate numbers and numbers found once in array.

View 7 Replies View Related

C++ :: Numbers Class - Translate Whole Numbers To English Description

Feb 4, 2015

I'm working on this program that I have to design a class Numbers that can be used to translate whole numbers to the English description of the number.

Now this is what I got so far:

#include <iostream>
#include <string>
using namespace std;
class Numbers {
private:
int number;
static string ones[];
static string tens[];

[Code] ....

The program seems to work. However its not giving me the right number description,

Example:

Please enter the amount you would like translated into words: 5
six dollars
please enter another number: 10
eleven dollars
please enter another number: 20
thirty dollars
please enter another number: 30
forty dollars
please enter another number: 100
two hundred dollars
please enter another number: 150
two hundred sixty dollars
please enter another number: 500
six hundred dollars
please enter another number: 1000
two thousand dollars
please enter another number:

View 4 Replies View Related

Visual C++ :: Ignoring Negative Numbers When Trying To Add Only Positive Numbers?

May 15, 2013

ignoring negative numbers when I am trying to add up only positive numbers.

SAMPLE:
if (num>=0) {
sum= sum + num;
}
else

how would the else in this case being a negative number not be included in the sum

View 4 Replies View Related

C :: Subset Combinations - Select All Numbers Right Or No Numbers Right

Dec 22, 2013

I need a list generated of all possible subset combinations for the set 1,2,3,4,5,6,7,8,9,10,12. Select six. Numbers cannot repeat.

Example subset: 1,2,3,4,5,6 (six selected, no repeats).

Example of what I dont need: 1,1,2,2,3,3,4,4,5,5,12,12 or 1,1,1,1,1,6.

I will also need the opposites removed, meaning...if I have 1,3,5,7,9,11 then I need 2,4,6,8,10,12 eliminated from the final list.

This is for a game, where you must select all numbers right or no numbers right.

View 2 Replies View Related

C/C++ :: Generate Combinations Of Numbers From 1 To 25 In 15 Numbers Array?

Sep 21, 2014

The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:

1 3 4 5 6 8 10 13 14 16 17 18 19 20 25

3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________

Count = 8, in this case..

I think it's not very difficult to do, but i just can't see how to do it.

#include <iostream>
#include <vector>
#include <numeric>

[Code]....

View 3 Replies View Related

C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30

May 20, 2014

I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.

#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!

[Code]...

View 5 Replies View Related

C/C++ :: Program That From 50 Numbers Displays Only Numbers Less Than 5

Jan 25, 2015

So i have made an array and made a scanf in a for loop so it can store all numbers entered from keyboard in the array but i dont know how to put the numbers that are less than 5 in another array and then print that array out and the lenght of the array.

View 11 Replies View Related

C :: Calculate Prime Numbers In Range And Return Count Of Prime Numbers

Apr 28, 2013

I wrote a program which sends a starting and ending range to other processes and the processes calculate the prime numbers in that range and return the count of prime numbers to the head process, process 0. But this is not working properly at the moment. I realize I still have to split up the range based on how many processes I have...I still have not figured out how I want to set that up. I

Code:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int isPrime(int num);
int main(int argc, char **argv){
}

[code]....

View 7 Replies View Related

C++ :: Read Stream Of Numbers From A File And Writes Only Positive Numbers To Second File

Mar 27, 2013

Write a program which reads a stream of numbers from a file, and writes only the positive numbers to a second file. The user should be prompted to enter the names of both the input file and output file in main(), and then main() will open both files. Another function named process() must then be called to read all the numbers from the input file and write the positive numbers to the output file. Note that you must pass the open stream variables for each file as arguments to the process() function, and that you need to (always) double check that the files opened successfully before using them.

This is what I have so far but its not working out!

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int process(ifstream &inf, ofstream &outf);

[Code] ....

View 1 Replies View Related

C++ :: Random Numbers - Getting Sum Of All Even And Odd Numbers

Aug 2, 2013

All Numbers are random.

This will be the output

Enter Number: 4
Enter Number: 3
Enter Number: 2
Enter Number: 1
Enter Number 6

The Sum of all even numbers is: 12
The Sum of all odd numbers is 4

View 18 Replies View Related

C++ :: How To Compare Two Max Numbers Out Of Four Numbers

Oct 4, 2013

i have trouble with comparing two of the biggest numbers out of four numbers. Im working on an assigment with a dice game where i need to tell the computer the following;

"if the biggest number out of dice_three and dice_four is the same number as the biggest of dice_two and dice_one, then loop1=true"

this is how i have been writing it so far ;

if
(MAXA(dice_three,dice_four) == MAX(dice_two,dice_one)){
lopp 1=true;
}

(as seen) i am using:

#define MAX(dice_one,dice_two) ( (dice_one) > (dice_two) ? (dice_one) : (dice_two) )
#define MAXA(dice_three,dice_four) ( (dice_three) > (dice_four) ? (dice_three) : (dice_four) )

to calculate which one is the biggest number out of the two pares. The code i have been writing so far seem to have the wrong syntax.

View 6 Replies View Related

C/C++ :: Add 00 To The End Of Numbers

Apr 21, 2014

If I have the number 88 how would I add 00 to the end of and turn it into 8800? Bitwise shifts is the only way I can think of to do this but it doesn't work. It completely changes the numbers.

View 6 Replies View Related

C :: Sum Of 5 Numbers Flowchart?

Nov 4, 2014

Design an algorithm using flowchart to prompt the user for 5 values. Total up all these values and print the total at the end of the program. If the number is equal to zero the system will terminate.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved