C++ ::  How To Display Numbers With Decimals

Aug 28, 2014

float put;
put = 6/120;
cout << put;

This outputs 0. Why is it so and how can I make it output 6/120 in a more precise way?

View 1 Replies


ADVERTISEMENT

C++ :: How To Display Result With Decimals

Nov 6, 2014

I am trying to make the code below display the result with decimals. I tried using setprecision, but I am not too sure where to put it. I placed it in cout section where the answer is but it still doesn't come out correctly.

#include <iostream>
using namespace std;
//*Delcare function prototype*
int ConvertToCentimeters (double, double );
//declare exception class*
class NegativeNumber

[Code] ....

View 4 Replies View Related

C++ :: Simple Way To Hold Numbers With Lot Of Decimals

Apr 8, 2013

I have a task to hold a number like 4.0000000000000000199e+30 and, in a variable like long double (the largest of the data type) doesn't hold the whole number, holds only 4.099e+30, like that.

Any way to hold the whole number?

View 1 Replies View Related

C++ :: Converting Decimals To Binary

Apr 28, 2013

I have written a code but i tried to alter it a little in this manner. But it seemed to not recognise what hexStack.getsize() > 0) is..??

while(hexStack.getSize() > 0)
{
//buffer being a previously declared int
buffer = hexStack.pop();

[Code]....

View 6 Replies View Related

C Sharp :: Adding 3 Decimals Places?

Apr 24, 2012

i wanted to add 3 decimals places to either string or int.

let say

scenario 1:

a = 8
to
a = 8.000
b = 11.6
to
b= 11.600
c= 34.55
to
c= 34.550

View 1 Replies View Related

C/C++ :: Converting Fractions To Decimals And Vice Versa

Aug 1, 2014

I'm working on a Fraction Class assignment where I'm supposed to provide conversion operators to allow Fraction objects to be used in expressions containing float data values. The way I have it now, I'm getting an error that says operator float(const Fraction &) must contain 'void', which makes no sense to me. Lines 155 - 173.

// Fractions CLASS
// Source: Fraction2012.cpp
// Author: Warren H. Knox, Jr.
// Date: 11/8/2012
#include <iostream>
#include <cstdlib>
using namespace std;
class Fraction {

[Code] ....

View 9 Replies View Related

C++ :: Display Only Numbers At The Last?

Aug 16, 2012

i want to to apply a validation for an field which is Vehicle number in that the last four should be digits for ex:

AP1234 something like this it and it shldnt have 0000 at the last ...

View 5 Replies View Related

C++ :: Display A Table Of Numbers From 50 To 150

Apr 2, 2013

Using for loop .....

View 15 Replies View Related

C++ :: Display Remainder Of The Square Of Numbers From 100 To 10

Mar 31, 2013

Display the remainder of the square of numbers from 100 to 10. This square of numbers must be divisible by the numbers from 100 to 10 respectively. what i need to in this

View 3 Replies View Related

C++ :: How To Display File With Numbers On The Screen

Apr 1, 2013

I have a file with numbers and want to display it on the screen.

View 15 Replies View Related

C++ :: Program That Display Prime Numbers From 1 To 100

Oct 4, 2014

This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.

#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()

[Code] ....

View 3 Replies View Related

C++ :: Program To Display First 40 Fibonacci Numbers

Feb 25, 2014

Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:

0, 1, 1, 2, 3, 5, 8, 13, 21,….

Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.

Here is what i have but i get errors!

#include <iostream>
using namespace std; {
int FirstNumber = 0;
int SecondNumber = 1;
int NumberOfNumbers = 2;
int NewNumber;

[Code] .....

View 3 Replies View Related

C++ :: Comparing Three Numbers And Display Largest

Oct 9, 2013

My display is producing:

Enter the first number:234
Enter the second number:2
Enter the Third number:3
The largest number is 3

#include <iostream>
using namespace std;
double larger(double n1, double n2, double n3);
int main() {

[Code] ....

View 1 Replies View Related

C++ :: Display Prime Numbers Using Loop

Feb 3, 2013

We were asked to make a program which displays the prime numbers within the range you inputted... like for example i entered 20 as the upper limit and 1 as the lower, then the program must display all prime numbers within 20 and 1..

and so my problem is, i get to display the prime numbers, but 2, 3, 5, and 7 can't because it think it's with the if statement i made within the loop? (Code below)

#include<iostream.h>
#include<conio.h>
void prime (int up, int low);
main() {
clrscr();
int Upper, Lower, i;

[Code] .....

View 6 Replies View Related

C++ :: Display All Composite Numbers From 0 To 1000?

Feb 21, 2013

Create a program that will display all the composite numbers from 0 to 1000 and has a maximum column of 5 . A composite number is a positive integer that has at least one positive divisor other than one or itself. In other words a composite number is any positive integer greater than one that is not a prime number.

SAMPLE OUTPUT:

4 6 8 9 10
12 14 15 16 18
20 21 22 24 25
26 27 28 30 32
....and so on.

View 6 Replies View Related

C++ :: Display Numbers In Binary Search Tree - Getting 0s

Jan 31, 2015

I want to display the numbers in a bst but all I get are 0s, what is wrong with my code that is causing this?

#include <iostream>
using namespace std;
class binarySearchTree {
private:
class TreeNode {
friend class binarySearchTree;
int value;

[Code] ....

View 1 Replies View Related

C++ :: Display Arithmetic Sequence After Adding All Numbers

Oct 7, 2013

This code is suppose to display arithmetic sequence after it has to add all the numbers together without a formula.

for example: the starting number is 5, common difference is 3, the term is 9

the sequence would display as: 5, 8, 11, 14, 17, 20, 23, 26, 29

the sum is: 153

with my code I've managed to get 8,11

To get the sum, I am restricted to using a "for" loop. For sequence, I am using a while. I am trouble developing the while loop to display the sequence and getting the sum for the for loop.

#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main() {
double a, d, n,i,sum,j;

[Code] ....

View 3 Replies View Related

C++ :: Using Array - Display Highest And Lowest Numbers

Oct 1, 2013

I have everything down except for the highest # and lowest number being displayed.

The arrays are 23, 4, 76, 89, 12, 43, 37, 67, 21, 14.

I have the average which is 38.6 but i stuck getting highest number and lowest.

View 7 Replies View Related

C :: Display Numbers That Are Passed As Literal ASCII Characters To LCD

Mar 20, 2014

What shall I learn in order to send values from 0.00 to 5.00? I'm working with they Hitachi 16x2 LCD display.I've been sending/displaying literal values on it all day.

Code:

SendCharater(unsigned char val)

where the variable val corresponds to the LCD character table.I can also send Hello World to the display, like so:

Code:

void putsXLCD(unsigned char *buffer){
while(*buffer) // Write data to LCD up to null
{
while( BusyXLCD() ); // Wait while LCD is busy
SendCharacter(*buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}

I could type in putsXLCD("5.00") in order to display it on the LCD, but how do I implement this automatically for values, e.g. 0.00 to 5.00?It appears I can only pass literal values through the function SendCharacter, meaning that in order to display "0" I have to pass the value 0x30 (the hex value of "0" on the LCD Table).

My current thought process:Much like passing "Hello World" in the function putsXLCD(), I need to assign a pointer that points at each value in the "array" that I need to send. E.g., I need to send 3.24, so I need to point to "3", fetch the corresponding hex value in the LCD table, in this case 0x34, and the pass this 0x34 into the SendCharacter function, and so on. So, if this is the case, how can I fetch the corresponding hex value?

View 7 Replies View Related

C :: Display Histogram Of 1000 Gaussian Distributed Numbers

Mar 5, 2013

I'm writing a program to display a histogram of 1000 Gaussian distributed numbers. I've generated the numbers using rand and now need to transform them. I have found the following formula to use

f(x) = exp(-x^2 / (2*sigma^2)) / sqrt(2*pi*sigma)

And I am unsure how to implement this into a function.

View 3 Replies View Related

C :: Read 15 Numbers And Display Each Number On Separate Line

Oct 21, 2014

Program to read in 15 numbers and display them as follows //each number on a separate line

Code:

# include <stdio.h>
# define MY_ARRAY 15
int main(){
int i ;
printf("please enter 15 numbers

[Code] ....

Error that i get from compiler:
Error E2062 array1.c 14: Invalid indirection in function main()
Error E2062 array1.c 19: Invalid indirection in function main()
both pointing to the separate "scanf"

View 6 Replies View Related

C++ :: User To Enter Decimal Value Then Display Its Corresponding Binary Numbers

Sep 13, 2013

Create a program that will ask the user to enter a decimal value (1-999999) then display its corresponding binary numbers. Repeat this process until the value entered is equal to 0. Use the following Function Prototype:

void BinCodes(int value);
Sample Input/Output:
Enter a Decimal: 35
Binary: 100011
Enter a Decimal: 184
Binary: 10111000
Enter a Decimal: 0

View 4 Replies View Related

C/C++ :: Program To Display First 10 Largest Numbers Present In A File?

Oct 15, 2012

there is a file contains only a numbers ,we dont know how many numbers present in that file.so i want a program to display top n largest number present in that fie.(n may be 5,10,12 like that.)

View 3 Replies View Related

C++ :: Program To Display All Fibonacci Numbers And 21st Digit Using Array

Mar 7, 2013

Create a program that display all the fibonacci numbers and display the 21st digit using array.

Here's my code:

#include <iostream>
using namespace std;
int main () {
cout<<" This program shows a series of fibonacci numbers
"<<endl;

[Code] ....

View 2 Replies View Related

C++ :: For Loop - Display Smallest And Largest Numbers From User Input

Jul 29, 2013

I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.

This is what I have ....

#include <iostream>
using namespace std;
int main() {
int amount;
int count;
int number = 0;
int smallest = 0;
int largest = 0;
cout << "Enter total numbers to process: ";

[Code] ....

View 4 Replies View Related

C++ :: Allow Users To Enter Any Two Positive Numbers And Then Display Results - Arithmetic Operators

May 14, 2013

The Program must allow users to enter any two positive numbers and then display the results.

#include <iostream>
using namespace std;
class ArithmeticOperators{
private:
int x;
int y;
public:
void set_values();

[Code] .....

View 2 Replies View Related







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