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


ADVERTISEMENT

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 View Related

C++ :: Function Should Not Display Anything But Resulting String Is Returned As A Result

Mar 2, 2014

c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:

A function recive: "housesinkbuildings" .The function returns: "house=sinkb=uildi=ngs" in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.

View 2 Replies View Related

C++ :: Prompt Information From User Then Display Result In One Dimensional Array

Apr 7, 2013

Is it possible to prompt information from user then display the result in a one dimensional array form? If yes, how should i link them together?

View 7 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++ :: 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 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/C++ :: Call To String Function To Display Names In Class Not Display

Apr 19, 2014

I created class called students which suppose to store students names of in array but when I call the display function it display only the first name. but I want it to display names depending on the array size.

#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;

[Code]....

View 3 Replies View Related

C :: Binary To Decimal Conversion Through A Port To Display On LCD Display

Dec 6, 2013

I know this is more simple than I am making it out to be. I have a solar panel hooked up to an 8-Bit ADC and linked into my Microprocessor. I am trying to take the Binary readout from the ADC and convert it to a decimal number to be displayed on the boards LCD display. I am wiring the ADC to PORTA on my Motorola Freescale Board. This is for a final project for my electronic systems class due on Monday...

View 3 Replies View Related

C :: Not Getting Required Result

Apr 30, 2013

Code:
void search(){void output(void);
char title[20],;
char *p;
clrscr();

[Code] ......

Info:Program that stores information about reports .the above function searches the report according to its title. list is the name of the structure that stores the records.

Why i'm using strstr:

for eg. there is a report titled 'report on tigers'

I want the report information to be output if someone searches for 'tiger'

Output:displays all the entries i have made till now

file is attached.

View 4 Replies View Related

C++ :: How To Pass By Value-Result

Dec 4, 2014

I'm trying to understand the pass by value-result. The code I have came up with so far only does by value and by reference, which I understand. The value-result is what has me stumped, and honestly I am unsure how to write the function for it. Here's my code so far...

#include <iostream>
using namespace std;
// Function prototypes.
void swapByValue(int, int, int);
void swapByRef(int&, int&, int&);

[Code] ....

View 4 Replies View Related

C++ :: Bad Value Result From Operator Using Objects

Jul 24, 2013

I keep getting an undesired value in this code. I've tried several methods, but none are giving me the correct answer. The out put is always zero, when in this case it should be 10!!

Here's the object structure:

template<class T, class _b>
struct quantity {
private: T value;
public:
explicit quantity(T val): value(val) {};
T getValue() { return value; };

[Code] .....

Here's the operation:

int main() {
quantity<int, bool> m(20);
quantity<float, bool> m_f(10);
quantity<double, bool> m_d(NULL);

m_d = m_f;

[Code] .....

Why does it seem that the assignment operator is the harder operator to overload? Maybe it's just my luck, but I seem to always run into issues whenever I work with it. I hardly ever experience errors when overloading any of the other operators.

View 6 Replies View Related

C++ :: Size Of Result With Struct Var

Apr 20, 2013

typedef struct Element Element;
struct Element {
char x;
double* y;

[Code] .....

This one with y pointer gives 8

typedef struct Element Element;
struct Element {
char x;
double y;

[Code] ....

This one with a normal y variable gives 12

View 7 Replies View Related

C/C++ :: How To Use Result Of If Statement Later On In The Code

Nov 19, 2014

how to use the result of an if statement in my program. I'm writing a program for a knockout tournament, so i want to extract the winner of each match to carry forward in the code for use in the next round. I've tried assigning another variable (#define r1w1) and saying that the variable = cName[0] or cName[1] in the if statements like this: (i did this because i thought i could then use r1w1 later in the code)

if(scorea1 > scoreb1) {
printf("
");
printf("WINNER OF ROUND 1 MATCH 1 IS %s
", cName[0]);
cName[0] = r1w1

[Code].....

View 1 Replies View Related

C# :: Program Keeps Adding 1 To Result?

Oct 21, 2014

I am creating a program that allows the user to enter the number of days worked and calculates the amount of money gained by doubling the amount from the previous day, starting with .01 cents. The program works fine except for in day 3, the program adds .01 along with doubling the amount from day 2. Also I must use a List Box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

[code]....

View 3 Replies View Related

C++ :: How To Bold Search Result

May 5, 2013

i need to know, that how i can get search result in bold format(using sequential search technique) from an array, in C++ graphic mode ???

e.g.

here is an array : 2 4 5 34 0 -45

and search key == 34

when it found 34 in array, '34' should bold to be prominent.

View 3 Replies View Related

Visual C++ :: Getting CURL Result In MFC?

Sep 27, 2014

I'm trying to messagebox the cURL result:

Code:
CURL *curl;
CURLcode res;
curl = curl_easy_init();

[Code]....

Is there anyway to messagebox the res value ?

View 2 Replies View Related

C :: How To Copy Result Of Printf Into Array

Oct 12, 2013

I am trying to compare 2 strings of characters The users input containing 5 chars is compared to a table If the input is already be existent in the table the index of those chars in the table is printed Quest: how to copy the result of a printf() into an array ? The last printf() gives a sequence of numbers and I am trying to save that sequence to another array for further operation ! I have not been able to do that so far even with tmp[]=i ;

Code:
#include <stdio.h>
#include <string.h>
#define N 30
#define n 100
int main (void)
[code]....

View 2 Replies View Related

C :: Getting Result To Print To A Text File

Apr 2, 2014

I am having a problem using fprintf. I have a function which flips a coin. Heads prints a text to the screen. Tails prints a different text to the screen. My problem is getting the result to print to a text file.

Code:

#include <stdio.h>
#include <stdlib.h>
#include<time.h>
void seedrnd(void);
int coinflip(int small, int large);
}

[code]....

View 12 Replies View Related

C++ :: Reverse Array - Unexpected Result

Jun 20, 2013

i use dev c++...i write this code to reverse an array and save the result in the same one

if n=3 i expect
a[0]=0 a[1]=1 a[2]=2 (before rev is OK but after calling rev)
a[0]=2 a[1]=1 a[2]=0 (expected result )
but i get
n=3

[code].....

View 4 Replies View Related

C++ :: Simple Calculator - Result Will Always Equal Zero

Jan 21, 2014

I'm making a simple calculator and have done it all right where you can input everything, all the functions are there, but when i run the program it will come to displaying the result and it will always equal zero, I just need it to say 8+8 = 16 rather than 8+8 = 0, i don't know whether its just displaying the results as 0, or not displaying it at all, the code will follow below:

Code:

#include<iostream>
using namespace std;
double num3;
double num2;
double result;
char operation;

[Code] ....

View 4 Replies View Related

C++ ::  How To Cout Boolean Result In Words

Dec 11, 2013

So I want to go from having 0 or 1 to having words like false or true. I did it with an if statement earlier today, but I had to get rid of the whole bool thing. I made the variable just a float. But he requires we use bool. Here is my code:

Car y;
cout << "Initial value for the Car: " << endl;
cout << "Age= " << y.getAge() << " years old. The Price= $" << y.getPrice() << endl;
y.setAge(8);
y.setPrice(12000);
y.setRaceCarStatus(true);
cout << "Modified value for the Car: " << endl;

[Code]...

I commented (//) the if statement that I had earlier. If I set RacecarStatus to True, is cout's 1. The starred (*) line right above the comments is the line that I was required to add. I want to cout the actual word true. The one I had this morning won't work anymore.

View 1 Replies View Related

C# :: Store Method Result In Array?

Feb 20, 2014

I do not have code - I am just wondering if I have a method which gets input from the keyboard and returns it, how would I store that information in a new method after calling it and put the result of it into an array.

View 3 Replies View Related

C++ :: Programme Crashes After Returning Result?

Nov 2, 2013

why my application actually crashes after it compute the area of a cross.

I output is correct but it crashes after it calculation is done.

cross.cpp
void Cross::setCrossCord()
{
for (int i=0; i<=12; i++)

[Code]....

View 2 Replies View Related

C/C++ :: Result Is Returning Address In Memory

Jun 30, 2014

The results of my code is supposed to be very simple: return the 2 integers and then their sum. However, it's doing returning the first value, then an address in memory(rather than the 2nd value), and then the 2nd value(rather than the sum). Here is the code:

#include <stdio.h>
#include <stdlib.h>
struct calculator{
double num1;
double num2;
double result;

[Code] .....

View 4 Replies View Related







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