Thread: Keeping Floating Numbers From Converting

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Keeping Floating Numbers From Converting

    I am writing a program that gives the user a number depending on the inputs they enter. In my matrix the numbers are entered in as floating numbers and when I run the program it converts the floating numbers to integers. How do I keep this from happening? I am still new to this. Thanks for the help.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    are you storing the numbers in an integer type?
    how are you printing the numbers to confirm that this is actually happening?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You are probably calling something that takes an integer and passing it a float.
    Something like SetDlgItemInt perhaps, which clearly takes an int?

    You'll need to show us some relevant bits of code.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2
    This is the part of my code where I have the floating numbers entered in my array.
    Code:
     
    #include <iostream>
    using namespace std;
    int main()
    {int opponents, odds;
    char firstcard, secondcard, handsuit;
    float pokerhandoddspreflop [2][9];
    pokerhandoddspreflop [0][0] = 0.2;
    pokerhandoddspreflop [0][1] = 0.4;
    pokerhandoddspreflop [0][2] = 0.6;
    pokerhandoddspreflop [0][3] = 0.8;
    This isnt all of the entries for the matrix, but it gives you an idea of what I am entering.
    Here is the part where I am having the if loops run and the values displayed.
    Code:
    if ( opponents == 1 && firstcard == 'A' && secondcard == 'A' && handsuit == 'o' ){
        odds = pokerhandoddspreflop [0][0];
    }
    if ( opponents == 1 && firstcard == 'A' && secondcard == 'A' && handsuit == 's' ){
        odds = pokerhandoddspreflop [0][0];
    cout << "Your pre-flop odds of winning with " << firstcard << secondcard << handsuit << " against " << opponents << " opponents are " << odds << " to 1" <<endl;
    I thought I wrote this correctly to display the value in the matrix but I'm not sure whats going on. Any help or suggestions would be greatly appreciated. Thanks

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Well odds is an int and in this line you are triggering an implicit conversion:
    Code:
    odds = pokerhandoddspreflop [0][0];
    You do this at least twice in the code you provided; since odds is an int, it has no choice but to be an int. Gawd that sounded almost zen...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting numbers from a string
    By Veneficvs in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2010, 08:43 AM
  2. "Unlimited" Length Floating Point Numbers
    By LuckY in forum C++ Programming
    Replies: 0
    Last Post: 03-22-2005, 07:49 PM
  3. Floating point numbers
    By noor_mirza in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2002, 03:40 AM
  4. converting numbers from one base to another
    By partnole in forum C++ Programming
    Replies: 4
    Last Post: 10-04-2001, 12:29 PM