This is because you are using the integer division version of operator/
, which takes 2 int
s and returns an int
. In order to use the double
version, which returns a double
, at least one of the int
s must be explicitly casted to a double
.
c = a/(double)b;
More Related Contents:
- Why uninitialized variable print a strange negative value? [duplicate]
- C++ while loop resetting variables?
- why this unexpected variable change happens? [closed]
- How do I store a value for later use?
- Integer division always zero [duplicate]
- Division result is always zero [duplicate]
- What is a reference variable in C++?
- Checking if a double (or float) is NaN in C++
- Why can’t variable names start with numbers?
- Variable initialization in C++
- how do I validate user input as a double in C++?
- How do I convert a double into a string in C++?
- dollar sign in variable name?
- Difference between static, auto, global and local variable in the context of c and c++
- When do function-level static variables get allocated/initialized?
- C++ decimal data types
- Are all integer values perfectly represented as doubles? [duplicate]
- Access variable value using string representing variable’s name in C++ [duplicate]
- How to make C++ cout not use scientific notation
- What happens to uninitialized variables? C++
- How do I get the type of a variable?
- Why floating point value such as 3.14 are considered as double by default in MSVC?
- Compare double to zero using epsilon
- How to generate random variable names in C++ using macros?
- c++ comparison of two double values not working properly [duplicate]
- how can I extract the mantissa of a double
- Should we generally use float literals for floats instead of the simpler double literals?
- converting a variable name to a string in C++
- generic way to print out variable name in c++
- Static global variables in C++