float m_fis;

This is a discussion on float m_fis; within the C++ Programming forums, part of the General Programming Boards category; I'm trying to convert an (typical) inputed value of 121115 to 12.99479 which would be (12' 11-15/16"). The values FFF-II-SS ...

  1. #1
    Ray Schmidt
    Guest

    Question float m_fis;

    I'm trying to convert an (typical) inputed value of 121115 to 12.99479 which would be (12' 11-15/16"). The values FFF-II-SS (F=feet/I=inches/S=sixteenths) is the norm in engineering dimentional input. Are there any suggestions on the best ways to tackel this.

    Thanks,
    Ray

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    How would you get 12.99479 out of 12' 11-15/16" on paper anyway? I can't figure it out :-)
    *Cela*

  3. #3
    Ray Schmidt
    Guest

    Convert

    input = 12.99479
    feet = 12
    inch = .99479 * 12 = 11.9375
    six = .9375 * 16 = 15

    12-11-15

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Is this sufficient?
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <string>
    
    using namespace std;
    
    int main()
    {
      string input;
    
      cout<<"Enter the dimensional input: ";
      getline(cin, input);
    
      int six = atoi(input.substr(input.length() - 2, 2).c_str());
      int inch = atoi(input.substr(input.length() - 4, 2).c_str());
      int feet = atoi(input.substr(0, input.length() - 4).c_str());
    
      double final = (((six / 16.0) + inch) / feet) + feet;
    
      cout<< final <<endl;
    }
    *Cela*

  5. #5
    Registered User Ray Schmidt's Avatar
    Join Date
    Feb 2003
    Posts
    17

    hmmm

    I have the input going through a GUI, defined to operate via radio button for decimal or FIS (float m_feet). Is it possiable to do this same thing without having to use the atoi? Is there a command or pointing proc. that will allow me to view a int at specific points? Or, will I have to use the itoa and then convert back.


    And thank you very much for the time you have taken' to work with me on this...

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>Or, will I have to use the itoa and then convert back.
    Breaking up an integer is a real pain, it's almost always better to convert it to a string and parse it like I did, then convert each of the parts back to integers for processing.

    >> Is it possiable to do this same thing without having to use the atoi?
    What you do with the input once you have it is your business, do what's most clear and easiest. What format is the input in? Is it in string, int, or floating point form when you get it? I assumed you got it as a string to begin with, that makes things way easier :-)
    *Cela*

  7. #7
    Registered User Ray Schmidt's Avatar
    Join Date
    Feb 2003
    Posts
    17

    I tried

    Not sure why this code is truncating (sorry)

    I tried using what you suggested and just had unexpected results. I'm sure I'm just doing it wrong but how do I get your code to work with this:

    void CRerayDlg::OnMessageButton2()
    {
    if (m_fis == 1) // Set to decimal
    {
    float worka=0;
    float workb=0;
    float workc=0;

    UpdateData(TRUE);
    worka = m_feet/2 + (m_overhang/12);
    workb = (((m_feet/2) + (m_overhang/12))*m_pitch)/12;

    worka = worka*worka;
    workb = workb*workb;
    workc = sqrt(worka+workb);

    m_feet2 = workc;

    m_feet2_c.EnableWindow(TRUE);
    UpdateData(FALSE);
    }

    if (m_fis == 0) // Set to sixteenths
    {

    UpdateData(TRUE);

    const int MAX=7;
    char string[MAX];

    _itoa(m_feet,string,2);

    int six = atoi(string.substr(string.length() - 2, 2).c_str());
    int inch = atoi(string.substr(string.length() - 4, 2).c_str());
    int feet = atoi(string.substr(0, string.length() - 4).c_str());

    double final = (((six / 16.0) + inch) / feet) + feet;
    m_feet2=final;


    MessageBox("Still Working On", "Whatever", MB_ICONEXCLAMATION);
    UpdateData(FALSE);

    }

    }



    C:\My Documents\Programming\Reray\RerayDlg.cpp(252) : error C2228: left of '.substr' must have class/struct/union type
    Last edited by Ray Schmidt; 02-02-2003 at 11:11 PM.

  8. #8
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Try this, I didn't know you were using C strings instead of C++ strings
    Code:
    void CRerayDlg::OnMessageButton2()
    {
      if (m_fis == 1) // Set to decimal
      {
        float worka=0;
        float workb=0;
        float workc=0;
    
        UpdateData(TRUE);
        worka = m_feet/2 + (m_overhang/12);
        workb = (((m_feet/2) + (m_overhang/12))*m_pitch)/12;
    
        worka = worka*worka;
        workb = workb*workb;
        workc = sqrt(worka+workb);
    
        m_feet2 = workc;
    
        m_feet2_c.EnableWindow(TRUE);
        UpdateData(FALSE);
      }
    
      if (m_fis == 0) // Set to sixteenths
      {
        UpdateData(TRUE);
    
        char string[8]; /* +1 for nul */
    
        sprintf(string, "%d", m_feet);
    
        int six = atoi(&string[strlen(string) - 2]);
        string[strlen(string) - 2] = '\0';
        int inch = atoi(&string[strlen(string) - 2]);
        string[strlen(string) - 2] = '\0';
        int feet = atoi(string);
    
        m_feet2 = (((six / 16.0) + inch) / feet) + feet;
    
        MessageBox("Still Working On", "Whatever", MB_ICONEXCLAMATION);
        UpdateData(FALSE); 
      }
    }
    You also need to include <cstdio> or <stdio.h>, <cstring> or <string.h>, but you probably knew that. :-)
    *Cela*

  9. #9
    Registered User Ray Schmidt's Avatar
    Join Date
    Feb 2003
    Posts
    17

    Thumbs up Thank You!!!

    That was it!!!

    Thanks...

    Ray Schmidt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 04:25 PM
  2. Replies: 14
    Last Post: 06-28-2006, 02:58 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21