Announcement

Collapse
No announcement yet.

C++ Programming Question

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    C++ Programming Question

    I am not to sure where to post this question but I thought that this would be the best place to put it. Here it goes.

    I am a noob c++ programmer, I make mistakes but I do learn from them. I am writing a program to mess around with classes and inheritance. I have everything thought out except for one thing. I am going to cite the problem/example.

    When the user selects a deposit and types in lets say 25.46; How do I get rid of the period. I do not want to use two integers values to store it. Thank you for your help.
    Proud to be Kubuntu user # 17587

    #2
    Re: C++ Programming Question

    Questions concerning specific programing languages should be asked in an appropriate forum for that purpose. Not trying to put you off here, but it doesn't seem as if your question belongs within this forum. Google searching on C++ forums finds many. May I refer you to one such:
    http://www.codeguru.com/forum/
    Using Kubuntu Linux since March 23, 2007
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Re: C++ Programming Question

      Will try to post in the right next time. ty for the help though.
      Proud to be Kubuntu user # 17587

      Comment


        #4
        Re: C++ Programming Question

        Snowhog already said it all about what the forum covers, but just to not leave you without an answer:
        - Store this float in a string, preferably a C type;
        - Loop through the string positions until you locate the ".";
        - Copy the contents before and after the "." to another string or just overwrite the "." by copying everything after it to their previous positions;
        - Don't forget to add the string terminator right after the last digit;
        - Copy the content of this string back to an integer variable.

        C++ has the "String" type from the STL, and there are many methods to manipulate the contents internally, like remove a character at a specific position. But I don't use it too often because many compilers differ in the implementation of the STL, for example, some define the type as "string", and others define as "String" (capital S). This by itself is a good argument to not make heavy use of it, now think of the internal differences of the methods and other types.
        G++ has good compliance, but there are many compiler-specific stuff, so code with that in mind.

        Comment


          #5
          Re: C++ Programming Question

          Well, I will have to agree with the previous thread. let me just expand a little of what he said. I use to code on C++ a little and I remember that there was two kind of string libraries. one was str and the other was string. If you check on the kind of functions that they have, you will be able to convert that floating variable into a string and then copy that string into a string variable the way you want it. In this case it will be the numbers before and after the period. I do not recall the function name exactly but a quick search will suffice. I would love to take a look at your code, let me know if you fix it. If you wish go to my profile and then email me the code.

          You can get me Using Threema: B6WSCFVY
          Mastodon: @pookito@latinos.social
          Jabber: pookito@neko.im

          Comment


            #6
            Re: C++ Programming Question

            Originally posted by DMurray
            Snowhog already said it all about what the forum covers, but just to not leave you without an answer:
            - Store this float in a string, preferably a C type;
            - Loop through the string positions until you locate the ".";
            - Copy the contents before and after the "." to another string or just overwrite the "." by copying everything after it to their previous positions;
            - Don't forget to add the string terminator right after the last digit;
            - Copy the content of this string back to an integer variable.

            C++ has the "String" type from the STL, and there are many methods to manipulate the contents internally, like remove a character at a specific position. But I don't use it too often because many compilers differ in the implementation of the STL, for example, some define the type as "string", and others define as "String" (capital S). This by itself is a good argument to not make heavy use of it, now think of the internal differences of the methods and other types.
            G++ has good compliance, but there are many compiler-specific stuff, so code with that in mind.
            Yah i do use g++ becasue it is complianet and I think it works the best. I had to use Visual Study for an class last semseter and oh boy was that not fun. It gave cryptic messages without line numbers and did not like looking for include files that I made myslef.
            Proud to be Kubuntu user # 17587

            Comment


              #7
              Re: C++ Programming Question

              Sorry to be a stick in the mud, but IMHO I would steer you right into std::string. I think manipulating strings in C is a pain! I have had good results with std::string and I think from a beginners point of view it will be a good fit.
              FKA: tanderson

              Comment

              Working...
              X