C/C++ :: What Data Type Is The Result Of Calculation On Int And Double

Jun 24, 2013

okay for instance
int x = 4;
double y = 2;  
printf("%d", (x / y + 5));

what data type is
(x / y + 5)
??

View 3 Replies


ADVERTISEMENT

C++ :: Possible To Use Data Type Double Or Float For Array?

Mar 9, 2014

Can you use data type double or float for an array? ie

double n[];
or
float a;
float m[a];

My code wont accept me changing the data type..will on accept int data type. I get the following error when I try to change the array to double or float..

3310E:C++vector.cpp[Error] invalid types 'double [1000][double]' for array subscript

View 4 Replies View Related

C++ :: In What Type Intermediate Result Of Expression Is Stored

Jan 8, 2013

my doubt is :- in what data type the intermediate result of an expression is stored? like for expression 2+3*1/2 , i think the intermediate result for 1/2 is stored in the form 0.5 but for expression 2+3*1/100 , i think the intermediate result for 1/100 is stored in the form 0.01 so i am not sure if the compiler use dynamic type ie, changes with need. or it always stores in high precision like:- for 1/2 its 0.5000 and for 1/100 also 0.0100 or something like that.

View 4 Replies View Related

C :: Calculate Number Of Bits In Type - Incorrect Result In Program

Feb 15, 2014

I have this simple program below:

Code:
#include <stdio.h>
#include <limits.h>
unsigned int rightrot(unsigned int x, unsigned int n) {

/* calculate number of bits in type */

size_t s = sizeof(x) * CHAR_BIT;

[Code] ....

The result it prints is 2684356604 on my 32-bit computer. The result I expect is as follows:
0xFF94 is 0000000000000000 1111111110010100 in binary.

Shift it right by 5:
0000000000000000 0000011111111100

Then take that result in shift it right by 27 (s is 32 and p is 5, so the difference is 27):
1111111110000000 0000000000000000

Now we use bitwise or:
0000000000000000 0000011111111100 | 1111111110000000 0000000000000000 = 1111111110000000 0000011111111100

That in decimal is 4286580732. So how does it come up with 2684356604?

View 2 Replies View Related

C++ :: Calculation Of Rectangular Area - Adding Data To Console

May 31, 2014

I wrote a little program. I'd like to calculation of rectangular area. How can I add data to the console?

Code:
#include <iostream>
using namespace std;
class Teglalap {
protected:
double hossz;
double szelesseg;
double terulet;

[Code] ....

But it is wrong. Nothing happen. Which line is wrong?

View 2 Replies View Related

C :: Can't Get A Double Type Output

Apr 1, 2014

this is what I got so far

Code:
#include <stdio.h>
#include <stdlib.h>
int main() {

[Code].....

he problem is that when I print out the three sums at the end of the program I dont get any decimal points but just zeros like something.00 instead of something.50 etc

View 3 Replies View Related

C++ :: Structured Data - Nesting Triangles Using Structs And Doing Some Geometric Calculation

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.

Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.

A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line. All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle. A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points). The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

What I need:

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/

[Code]....

View 2 Replies View Related

C++ :: Structured Data / Nesting Triangles Using Structs And Doing Some Geometric Calculation?

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line.

All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle.

A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points).

The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/
struct Point {
double x;
double y;

[code]...

View 1 Replies View Related

C/C++ :: Use Modulus Operator With Double Type Variables?

Mar 13, 2013

how can we use modulus operator with double type variables

View 2 Replies View Related

C++ :: No Operator Found Which Takes A Right-hand Operand Of Type Double

May 17, 2014

while (getline(inStream, line))
{
while (inStream >> Student.getId() >> Student.FNAME >> Student.MINIT >> Student.LNAME >> Student.GENDER >> Student.UNITS >> Student.getGpa())
{
while (Student.getId() != id)
{
outStream << line << endl;
}
}
}

This is what I have right now. It shouldn't be a problem, but for some reason I am getting an error trying to >> Student.getGpa()

Error1error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'double' (or there is no acceptable conversion)c:location1301Project 5

I will post more code if needed, but... I just don't know. I have a TON of code so I would rather not if I don't have to.

View 2 Replies View Related

C++ :: Pass Double Pointer Of Object Into A Node Of Self Similar Type?

Nov 30, 2014

The following code compiles and runs fine till it reaches line 16 and gets a sigsev violation which I'm not sure about as to why. I have no problem passing the object of type node** into the constructor of base and storing it into the double pointer node** copy;; but when I call the function void pass(node** temp) it crashes.

#include <iostream>
class base;
class node {
private:
node** data;
public:

[Code] .....

View 3 Replies View Related

C :: Function That Merge Content Of Two Sorted Arrays Of Double Type Values

Nov 4, 2013

I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.

Here is my program so far - I know there is alot of errors and mistakes:

Code:

#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {

[Code]...

View 2 Replies View Related

C :: Create New Data Type Data Declared As Int

Feb 1, 2015

I'm trying to create a new data type Data declared as int. What comes up to my mind is to create a structure like

Code:

typedef struct Data {
int number;
} Data;

but when I need to use the data I need to go through the structure. Is this a good way to declare a new data type?

View 2 Replies View Related

C++ :: Function To Initialize Double Data Array Element To 0.0

Apr 25, 2013

ok here is the question: Write a function that will initialize a double data array element to 0.0 ?

View 4 Replies View Related

C++ :: How To Convert String To Double Without Changing Actual Data

Jun 3, 2013

I have to convert string to double. i'm using "atof" function to achieve same.

I have string as "0.0409434228722337" and i'm converting with "atof" But i'm getting double value as "0.040943422872233702". Why it adds 02 additionally at the end?

More example :

"0.0409434228722337" converts to "0.040943422872233702"
"0.067187778121134" converts to "0.067187778121133995"

Is there any other possibility to convert string to double without changing data ?

View 5 Replies View Related

C++ :: Type Conversion - Float Or Double Variable Into Unsigned Char Variable And Back

May 10, 2013

I would like to convert a float or double variable into unsigned char variable and back.

float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);

I am not getting the same value back.. why?

View 2 Replies View Related

C++ :: Float And Double Data Types - Cannot Store Infinite Numbers

Sep 6, 2013

I was working on float and double data types and to see the results i wrote this program:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
ofstream outputF("output.txt");
double a = 1;
double outcome;

[Code] ....

Well I understand the part it cannot store infinite numbers. but if you take a look at the output for example (since it is too long i just added some of the outputs)

//---------------------
for the value of : 001
1
//---------------------
for the value of : 002
0.5
//---------------------
for the value of : 003
0.3333333333333333148

[Code] ....

if you look carefully at the value "5" and "10" results. it is awkwardly abnormal. which is something i couldnt understand. also it is the same with value "20", "25", "40", "50" and so on.

View 5 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C++ :: Creating INF Data Type?

Jan 21, 2015

I want to create a new data type called an inf_t. It's basically infinity (which for C++ is 1.7e+308). The only reason I want this is because I want to overload the cout << operation to print out INF/inf. Should I do this in a struct?

Code: struct inf_t {
private:
double inf = 1.7e+308;
};
std::ostream& operator << (std::ostream &stream, inf_t inf) {
stream << "INF";
return stream;
}

View 4 Replies View Related

C :: Size Of The Data Type

Mar 4, 2014

I want to find the size of the data type with out using sizeof() operator.

View 9 Replies View Related

C :: Data Type For Date

May 18, 2014

If I am asked to declare a data type for Date which should be in the format DD/MM/YY, which data type should i use for it? Is there any data type known as Date in C?

View 2 Replies View Related

C/C++ :: Defining 3 Bit Or 12 Bit Data Type

Apr 9, 2015

Is there a way to define a 3 bit or 12 bit data type in C/C++. I need these for defining my own packet having different bit length fields.

View 1 Replies View Related

C++ :: Char Data Type Variable

Jun 12, 2013

I have two char variables, m_GPSOffset[13] and m_FileName[100]. When m_GPSOffset has a value assigned to it, say for instance +11:25:30. The first entry of the value, in this case +, is always stored in m_FileName. I am clueless on why this is occurring.

View 15 Replies View Related

C++ :: What Data Type To Treat Input As

Sep 3, 2013

I know that an int is usually 4 bytes, ranging from -2^31 to 2^31-1 for a signed int and 0 to 2^32-1 for an unsigned int. My question is simply, bit-wise (I know they are labelled in the code), how does it determine whether to show -2^31 or 2^32-1 if it was 11111111 11111111 11111111 11111111 in bits? Is there a 5th byte to tell the compiler what data type to treat the input as?

View 3 Replies View Related

C++ :: Integer Max - Long Data Type

Jan 4, 2013

Working on a Project Euler problem and the question asks for the largest prime number that is a factor of 600851475143. As you can see, this is significantly larger than the maximum of a long data type, which maxes out at 2147483647.

I'm running on Windows 32, so int64 is not a valid option for me. It seems like I'll likely have to use a different language to solve this problem.

View 4 Replies View Related

C++ :: Finding Out Input Data Type?

Oct 15, 2013

I'm currently trying to solve a programming assignment and i got the logic of it, however i find it hard to implement.

What i need to do basically is fill an array with objects. Each object is a class that contains only one type of data. This means i can place int, double and string for example in one simple array.

However i can't figure out how to read data and then decide what it is. Even if i use templates once i call the function i have to give it a type, so getType<int> for example will not work with double or string.

I know about typeID and how to use it, i just can't figure out where to use it.

View 2 Replies View Related







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