Thread: mathematical calculations

  1. #1
    Unregistered
    Guest

    Red face mathematical calculations

    good evening all,

    I need to write code for a program that takes the number from the edit box "hours worked", multiplies it by the edit box "pay rate" and when I click the button calculate pay it spits the total of "hours worked" by "pay rate" into the edit box "total pay"

    All help is appreciated
    Jim

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    And you have a problem with what in that?

    What compiler / OS / language (C or C++) are you using?
    Have you got the basic program, dialog, callback?
    Are you getting the user input?

    Use GetDlgItemText() and atof() to get the float and sprintf() and SetDlgItemText() to put it back in the final edit.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Unregistered
    Guest

    Lightbulb

    Thank you for your response. Sorry I did not include the info you requested. I am doing this in c++. I have the basic dialog, and edit boxes with labels. I have the edit boxes for the numbers set at bool variable so that it knows there are supposed to be numbers

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    So look up GetDlgItemText() as suggested, or possibly GetDlgItemInt() if you are only allowing integer values in your edit boxes. These API calls allow you to retrieve the contents of an edit box, (amongst other things), into a variable in your program. Manipulate the values as appropriate. Then SetDlgItemText() does the opposite, it allows you to set the contents of an edit box, (amongst other things), to a variable in your program.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Unregistered
    Guest
    Adrian and Novacain, thanks for your help, I tyhink I am getting closer to finishing this up. My problem is where to use the getDlgitemint() do I use it after the code for the edit box? How to I then manipulate the values to get the total in the edit box for total pay?

    Jim

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    When use use GetDlgItemInt it returns the int in the DlgItem you specified, so you have to make a variable equil to the function's return. As for using it after the code for the edit box, I would make a button that, when pressed, does the multiplication and output. To check if a button if pressed you check for the WM_COMMAND message, and then check the LOWORD of the WParam to see if it was your button. Then in that case statement do all the output stuff. Here is an example:
    Code:
    case WM_COMMAND:
        switch(LOWORD(wParam)){
              case ID_BUTTON:  //The buttons control ID
               do everything in here.........         
               break;
         }
    break;

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Under the WM_COMMAND switch, in the buttons case.

    Use
    Code:
    case IDC_TOTAL_BUTTON://your buttons ID
    if(BN_CLICKED == HIWORD(wParam))
    //do the math
    //display results
    break;
    to find if the button was clicked (may not need this as few other msg's are sent to buttons but is good practice), then do the math and use the SetDlgItemInt() to put the result into the right edit ctrl.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Unregistered
    Guest

    Smile

    Hey All I di it, Ifound a simple program on codeproject and modeled my problem after it. Thanks for all the Help. See you all soon

    JIM

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doing calculations on a data file
    By bassist11 in forum C Programming
    Replies: 2
    Last Post: 03-30-2009, 07:47 PM
  2. Mathematical Operation
    By madahmad1 in forum C Programming
    Replies: 29
    Last Post: 07-30-2008, 09:58 AM
  3. C program compile but not doing the calculations
    By abs.emailverify in forum C Programming
    Replies: 8
    Last Post: 11-08-2006, 08:43 AM
  4. writing mathematical operations in C
    By p_s_ross in forum C Programming
    Replies: 2
    Last Post: 06-13-2003, 03:04 AM
  5. How do I get these calculations correct?
    By nadeni0119 in forum C++ Programming
    Replies: 10
    Last Post: 04-07-2003, 11:09 AM