how to align things

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    Originally posted by kenvin100
    it works a little but there's still some problem..appara ntly items with larger names arent jusitifed..subt raction sign is space

    item---------------------------- quantity@price. ..
    item------------------------------------------------------------quantity@price. ..

    see the problem?
    May you please post the code that produced the above output

    Comment

    • kenvin100
      New Member
      • Oct 2006
      • 24

      #17
      i think u misunderstood wat im supposed to do...im supposed to align the prices to the right regardless the length of the item

      Comment

      • kenvin100
        New Member
        • Oct 2006
        • 24

        #18
        no problem...i used string out instead..

        String out = "";
        int space = 0;
        int spaces = 50 - item.length();

        out = ""; //declare the variable space
        for(int i = 0 ;i < 27; i++) {
        out += " "; //
        }

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #19
          Originally posted by kenvin100
          i think u misunderstood wat im supposed to do...im supposed to align the prices to the right regardless the length of the item
          That's what I thought you wanted to do

          Comment

          • kenvin100
            New Member
            • Oct 2006
            • 24

            #20
            maybe i need an if statement

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #21
              Originally posted by kenvin100
              no problem...i used string out instead..

              String out = "";
              int space = 0;
              int spaces = 50 - item.length();

              out = ""; //declare the variable space
              for(int i = 0 ;i < 27; i++) {
              out += " "; //
              }
              What is the 27 doing there. You are supposed to put spaces as in
              Code:
              for(int i = 0 ;i < spaces; i++)

              Comment

              • kenvin100
                New Member
                • Oct 2006
                • 24

                #22
                wat does 50-item.length(); mean

                Comment

                • kenvin100
                  New Member
                  • Oct 2006
                  • 24

                  #23
                  k im almost there..its almost aligned
                  output:

                  apple 1@1.0
                  fresh baked bread1@1.0

                  i just need to solve this problem (dont ask why i put fresh baked bread..laughs)

                  Comment

                  • kenvin100
                    New Member
                    • Oct 2006
                    • 24

                    #24
                    Yes I Got It!! Thanks Man!!

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #25
                      Originally posted by kenvin100
                      wat does 50-item.length(); mean
                      item1------------------------------------------20
                      myItem2--------------------------------------30
                      mylongerItem-------------------------------40

                      The area marked --------------------- is what we are trying to construct and store it as space(variable) ;
                      First we have to know how many dashs (spaces).
                      Suppose that where we have the 20, 30, 40 is exactly 50 spaces from the left of the screen. Then spaces = 50 - item1.length();

                      Comment

                      • kenvin100
                        New Member
                        • Oct 2006
                        • 24

                        #26
                        k...there's only one problem..let me show u..

                        item------ quantity@1.0
                        item-------quantity@2.06

                        the problem here is that if the price has two decimals, (eg 12.46), the alignment is off..how do i solve this

                        Comment

                        • kenvin100
                          New Member
                          • Oct 2006
                          • 24

                          #27
                          since there's supposed to be aligned at the right side so im trying adding spaces but it doesnt work

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #28
                            Originally posted by kenvin100
                            since there's supposed to be aligned at the right side so im trying adding spaces but it doesnt work
                            Restrict the output to 2 decimal places only. 1.0 becomes 1.00

                            Comment

                            • kenvin100
                              New Member
                              • Oct 2006
                              • 24

                              #29
                              um all i kno how to do is to make numbers with two decimal places..im usin that in this code like if the person puts 1.0695, it outputs as 1.07

                              Comment

                              • kenvin100
                                New Member
                                • Oct 2006
                                • 24

                                #30
                                its just that if i put something like 12.46, its not aligned

                                apple 1@1.06
                                fresh baked bread 1@12.46


                                see the problem?

                                Comment

                                Working...