How do I get decimals in C++ if I'm using integer variables

Michael Webb

Here's my code:

class Division{
public:
    void div(){
    //This is what to use inside the main
    //Division Divide;
    //Divide.div();
    int x;
    int y;
    int div;
    cout << "Still in Alpha So it only rounds the Number\n";
    cout << "Enter Your Number\n";
    cin >> x;
    cout << "Divided by\n";
    cin >> y;
    cout <<  "=";
    div = x/y;
    cout <<  div;
Eduardo Soriano

You can't if you define them as int. Try with double or float instead.

double x;
double y;
double div;

Changing the definition solves the problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I deal with C# decimals when using IronPython?

From Dev

How do I format decimals in C?

From Dev

How do I get this program to allow decimals to be entered?

From Dev

How do I set the number of decimals in a Numbers cell using AppleScript?

From Dev

How do I get the integer value of an enum?

From Dev

How do I get a UITextField input as an Integer

From Dev

How do I decide how many decimals, I should use for my float in c

From Dev

How do I decide how many decimals, I should use for my float in c

From Dev

How do I get the absolute value of an integer without using Math.abs?

From Java

How do I get the current username in .NET using C#?

From Dev

How do I hide text in a GUILayout.TextField in Unity (I'm using c# to do this)?

From Dev

How do I get the maven dependency:tree command to show when I'm using a RELEASE version?

From Java

How do I reverse the order of the digits of an integer using recursion in C programming?

From Dev

How do I get this HashMap<Integer[], Integer> to work the way I want it to?

From Dev

How do I get an IntStream from a List<Integer>?

From Dev

How do I get a specific bit from an Integer in Swift?

From Dev

How do I get machine-sized integer for FFI?

From Dev

How do I perform integer division, and separately get the remainder, in JavaScript?

From Dev

How do I store numbers in C++ without the decimals being truncated?

From Dev

C programming: why are my decimals not displaying & how do I define black spaces

From Dev

Using LINQ, how do I get rows M through M+N?

From Dev

How do I get the sum of columns from a csv within specified rows using dates inputting as variables in python?

From Dev

How do I get to a certain place in my JavaScript object using variables?

From Dev

How do I randomly get variables from a mysql database? (using php with dbo connection)

From Dev

How do I set integer endianness using htonl in Swift?

From Dev

How do I write an integer value to a csv file using opencsv

From Dev

How do I convert an NSString to an integer using Swift?

From Dev

How do I parse an integer, using the rule that +5 is not valid but 5 is?

From Dev

How do I display an integer with a function that only accepts a char in C?

Related Related

  1. 1

    How do I deal with C# decimals when using IronPython?

  2. 2

    How do I format decimals in C?

  3. 3

    How do I get this program to allow decimals to be entered?

  4. 4

    How do I set the number of decimals in a Numbers cell using AppleScript?

  5. 5

    How do I get the integer value of an enum?

  6. 6

    How do I get a UITextField input as an Integer

  7. 7

    How do I decide how many decimals, I should use for my float in c

  8. 8

    How do I decide how many decimals, I should use for my float in c

  9. 9

    How do I get the absolute value of an integer without using Math.abs?

  10. 10

    How do I get the current username in .NET using C#?

  11. 11

    How do I hide text in a GUILayout.TextField in Unity (I'm using c# to do this)?

  12. 12

    How do I get the maven dependency:tree command to show when I'm using a RELEASE version?

  13. 13

    How do I reverse the order of the digits of an integer using recursion in C programming?

  14. 14

    How do I get this HashMap<Integer[], Integer> to work the way I want it to?

  15. 15

    How do I get an IntStream from a List<Integer>?

  16. 16

    How do I get a specific bit from an Integer in Swift?

  17. 17

    How do I get machine-sized integer for FFI?

  18. 18

    How do I perform integer division, and separately get the remainder, in JavaScript?

  19. 19

    How do I store numbers in C++ without the decimals being truncated?

  20. 20

    C programming: why are my decimals not displaying & how do I define black spaces

  21. 21

    Using LINQ, how do I get rows M through M+N?

  22. 22

    How do I get the sum of columns from a csv within specified rows using dates inputting as variables in python?

  23. 23

    How do I get to a certain place in my JavaScript object using variables?

  24. 24

    How do I randomly get variables from a mysql database? (using php with dbo connection)

  25. 25

    How do I set integer endianness using htonl in Swift?

  26. 26

    How do I write an integer value to a csv file using opencsv

  27. 27

    How do I convert an NSString to an integer using Swift?

  28. 28

    How do I parse an integer, using the rule that +5 is not valid but 5 is?

  29. 29

    How do I display an integer with a function that only accepts a char in C?

HotTag

Archive