Need help.

Author Message
Funkeyy

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 8/8/2011
  • Status: offline
Need help. Monday, August 08, 2011 8:19 PM (permalink)
0
Well this should be simple. but I'm just horrible at this.
These are the two questions:

Question C
A paving company needs a simple program to calculate the number of pavers required per square metre. Regular sized pavers need 9 pavers per square metre, the smaller pavers require 16 pavers to make a square metre. When given the area to be covered in square metres, output the number of pavers that will be required for the job.

Question D
Modifications are required to the program created in question C. You must amend all aspects of the analysis; Input, rules and processing and output, design algorithm before editing the code; your amended algorithm must allow for all the modifications requested.

The paving company would also like the program to calculate the total order cost. Pavers are sold by the square metre, the price per square metre varies depending on the quality and supplier, get the price per square metre and calculate the cost of the order (square metres required is already known). A loyalty discount is given to regular customer; if the customer has a loyalty card they receive a 5% discount on the order cost. Display the total cost of the order.

This is the answer to question C:
Option Explicit
Dim r_paver
Dim s_paver
Dim paver_type
Dim s_meters
Dim pavers

r_paver = 9
s_paver = 16
paver_type = InputBox("Do you need Regular or Small pavers? Answer R or S.")
s_meters = InputBox("How many square meters need to be covered?")

IF paver_type = "r" OR paver_type = "R" THEN
pavers = r_paver * s_meters
ELSE
pavers = s_paver * s_meters
END IF

MsgBox "You need " & pavers & " pavers.", vbInformation

Now I just need the answer to question D.
 
Thanks to anyone who can help me with this. 
 
#1
    ehvbs

    • Total Posts : 3320
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    Re:Need help. Monday, August 08, 2011 10:10 PM (permalink)
    0
    Please post question A and B.
     
    #2
      Funkeyy

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 8/8/2011
      • Status: offline
      Re:Need help. Monday, August 08, 2011 10:31 PM (permalink)
      0
      Question A and B have nothing to do with these 2 questions.
       
      #3
        ehvbs

        • Total Posts : 3320
        • Scores: 110
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        Re:Need help. Tuesday, August 09, 2011 12:30 AM (permalink)
        0
        Then you should ask your teacher/author of the book you are learning from, why
        on earth (s)he encourages you to

        • hack away without a plan to solve problem(s) (Question C) before thinking about them (Question D)
        • use InputBox for getting the program's parameters; because the information has to be entered for each (test) run and disappears immediately, InputBox isn't suitable neither for development nor production. If the parameters for 'real world' scripts must be obtained by a GUI, you should use a .HTA
        The abstract structure of you paving problem is to compute the product of
        two numbers: the number of squares to pave amd the number of pavers (tiles?)
        to cover one square. The second depends on the type (regular or small) of the
        pavers.

        So you should start with a proof of concept script like this:

          
         Const cnRegPavPerSq =  9  
         Const cnSmlPavPerSq = 16  
         Dim aTests : aTests = Array( _  
         Array( "r",  0, 0 ) _  
         , Array( "s",  0, 0 ) _  
         , Array( "x",  0, 0 ) _  
         , Array( "r",  1, cnRegPavPerSq ) _  
         , Array( "s",  1, cnSmlPavPerSq ) _  
         , Array( "s", 10, cnSmlPavPerSq * 10 ) _  
         )  
         Dim aTest  
         For Each aTest In aTests  
         Dim nFak : nFak = 0 ' used as error indicator  
         Select Case aTest( 0 )  
         Case "r"  
         nFak = cnRegPavPerSq  
         Case "s"  
         nFak = cnSmlPavPerSq  
         Case Else  
         WScript.Echo "bad paver type", aTest( 0 )  
         End Select  
         If 0 <> nFak Then  
         Dim nRes : nRes = aTest( 1 ) * nFak  
         WScript.Echo aTest( 1 ), "sq need(s)", nRes, "type", aTest( 0 ), "paver(s)", "(", CStr( nRes = aTest( 2 ) ), ")"  
         End If  
         Next  
         

        output:
          
         0 sq need(s) 0 type r paver(s) ( True )  
         0 sq need(s) 0 type s paver(s) ( True )  
         bad paver type x  
         1 sq need(s) 9 type r paver(s) ( True )  
         1 sq need(s) 16 type s paver(s) ( True )  
         10 sq need(s) 160 type s paver(s) ( True )  
         

        that tests different parameter sets and reflect the fact that there are just
        two types of tiles. The first enhancement is to allow for a third type of pavers
        and to implement a check on the number of squares too:
          
         Const cnRegPavPerSq =    9  
         Const cnSmlPavPerSq =   16  
         Const cnMinPavPerSq =   25  
         Const cnMaxSquares  = 1000  
         Dim aTests : aTests = Array( _  
         Array( "r",    0, 0 ) _  
         , Array( "s",    0, 0 ) _  
         , Array( "x",    0, 0 ) _  
         , Array( "r",    1, cnRegPavPerSq ) _  
         , Array( "s",    1, cnSmlPavPerSq ) _  
         , Array( "s",   10, cnSmlPavPerSq * 10 ) _  
         , Array( "m",   10, 249 ) _  
         , Array( "m",   10, 250 ) _  
         , Array( "m",   -1,   0 ) _  
         , Array( "m",  999, cnMinPavPerSq *  999 ) _  
         , Array( "s", 1000, cnSmlPavPerSq * 1000 ) _  
         , Array( "r", 1001, -1 ) _  
         )  
         Dim aTest  
         For Each aTest In aTests  
         Dim nFak : nFak = 0 ' used as error indicator  
         Select Case aTest( 0 )  
         Case "r"  
         nFak = cnRegPavPerSq  
         Case "s"  
         nFak = cnSmlPavPerSq  
         Case "m"  
         nFak = cnMinPavPerSq  
         Case Else  
         WScript.Echo "bad paver type", aTest( 0 )  
         End Select  
         Select Case True  
         Case Not IsNumeric( aTest( 1 ) )  
         WScript.Echo "not numeric", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         Case 0 > aTest( 1 )  
         WScript.Echo "bad squares", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         Case cnMaxSquares < aTest( 1 )  
         WScript.Echo "bad squares", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         End Select  
         If 0 <> nFak Then  
         Dim nRes : nRes = aTest( 1 ) * nFak  
         WScript.Echo aTest( 1 ), "sq need(s)", nRes, "type", aTest( 0 ), "paver(s)", "(", CStr( nRes = aTest( 2 ) ), ")"  
         End If  
         Next  
         

        This can be enhanced to a script that can nearly be used in production:
          
         Const cnRegPavPerSq =    9  
         Const cnSmlPavPerSq =   16  
         Const cnMinPavPerSq =   25  
         Const cnMaxSquares  = 1000  
         Dim aTest : aTest    = Array( "r", 1, cnRegPavPerSq )  
         Dim oWAU  : Set oWAU = WScript.Arguments.Unnamed  
         On Error Resume Next  
         If 1 <= oWAU.Count Then aTest( 0 ) = Left( oWAU( 0 ), 1 )  
         If 2 <= oWAU.Count Then aTest( 1 ) = CLng( oWAU( 1 ) )  
         If 0 <> Err.Number Then  
         WScript.Echo Err.Description  
         WScript.Quit 1  
         End If  
         On Error GoTo 0  
         Dim nFak  : nFak = 0 ' used as error indicator  
         Select Case aTest( 0 )  
         Case "r"  
         nFak = cnRegPavPerSq  
         Case "s"  
         nFak = cnSmlPavPerSq  
         Case "m"  
         nFak = cnMinPavPerSq  
         Case Else  
         WScript.Echo "bad paver type", aTest( 0 )  
         End Select  
         Select Case True  
         Case Not IsNumeric( aTest( 1 ) )  
         WScript.Echo "not numeric", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         Case 0 > aTest( 1 )  
         WScript.Echo "bad squares", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         Case cnMaxSquares < aTest( 1 )  
         WScript.Echo "bad squares", aTest( 1 )  
         nFak = 0 ' used as error indicator  
         End Select  
         If 0 <> nFak Then  
         Dim nRes : nRes = aTest( 1 ) * nFak  
         WScript.Echo aTest( 1 ), "sq need(s)", nRes, "type", aTest( 0 ), "paver(s)"  
         End If  
         

        Test it with
          
         cscript pave.vbs => 1 sq need(s) 9 type r paver(s)  
         cscript pave.vbs s => 1 sq need(s) 16 type s paver(s)  
         cscript pave.vbs s 100 => 100 sq need(s) 1600 type s paver(s)  
         cscript pave.vbs r notanumber => Type mismatch  
         

        The polishing needed for selling the script is postponed.

        To deal with the additional parameters (Question D), you systematically expand
        the first version of the script:
          
         Const cnRegPavPerSq =  9  
         Const cnRegPrice    = 16  
         Const cnSmlPavPerSq = 16  
         Const cnSmlPrice    =  9  
         Const cnReduce      = 0.95  
         Dim aTests : aTests = Array( _  
         Array( "r",  1, cnRegPavPerSq, cnRegPavPerSq * cnRegPrice, 9 * 16 * cnReduce ) _  
         , Array( "s",  1, cnSmlPavPerSq, 9 * 16, cnRegPavPerSq * cnRegPrice * 0.95 ) _  
         )  
         Dim aTest  
         For Each aTest In aTests  
         Dim nFak   : nFak   = 0 ' used as error indicator  
         Dim nPrice  
         Select Case aTest( 0 )  
         Case "r"  
         nFak   = cnRegPavPerSq  
         nPrice = cnRegPrice  
         Case "s"  
         nFak   = cnSmlPavPerSq  
         nPrice = cnSmlPrice  
         Case Else  
         WScript.Echo "bad paver type", aTest( 0 )  
         End Select  
         If 0 <> nFak Then  
         Dim nRes  
         nRes = aTest( 1 ) * nFak  
         WScript.Echo aTest( 1 ), "sq need(s)", nRes, "type", aTest( 0 ), "paver(s)", "(", CStr( nRes = aTest( 2 ) ), ")"  
         nRes = nRes * nPrice  
         WScript.Echo "Full Costs:", nRes, "(", CStr( nRes = aTest( 3 ) ), ")"  
         nRes = nRes * cnReduce  
         WScript.Echo "Reduced Costs:", nRes, "(", CStr( nRes = aTest( 4 ) ), ")"  
         End If  
         Next  
         

        output:
          
         1 sq need(s) 9 type r paver(s) ( True )  
         Full Costs: 144 ( True )  
         Reduced Costs: 136,8 ( True )  
         1 sq need(s) 16 type s paver(s) ( True )  
         Full Costs: 144 ( True )  
         Reduced Costs: 136,8 ( True )  
         

        <message edited by ehvbs on Tuesday, August 09, 2011 12:33 AM>
         
        #4
          Funkeyy

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 8/8/2011
          • Status: offline
          Re:Need help. Tuesday, August 09, 2011 2:26 AM (permalink)
          0
          Whoa, way to go advanced on my ass.
          I'm just learning, thus why what I posted was just basic. I was only expecting a basic anwer.
           
          Thanks for your input though, only problem is I won't understand it 
          <message edited by Funkeyy on Tuesday, August 09, 2011 2:27 AM>
           
          #5
            ehvbs

            • Total Posts : 3320
            • Scores: 110
            • Reward points : 0
            • Joined: 6/22/2005
            • Location: Germany
            • Status: offline
            Re:Need help. Tuesday, August 09, 2011 2:44 AM (permalink)
            0
            Don't be a coward, copy & paste the first script as e.g. pave.vbs to a sutable folder, open a command prompt, change to that directory and start the the script using
            cscript pave.vbs
            and
            cscript pave.vbs //X
            for a step by step debugging session. Feel free to ask for more detailed explanations of the code (or the surprises when trying to run the script), by asking specific questions.
             
            #6
              Funkeyy

              • Total Posts : 4
              • Scores: 0
              • Reward points : 0
              • Joined: 8/8/2011
              • Status: offline
              Re:Need help. Tuesday, August 09, 2011 3:26 AM (permalink)
              0
              When I said I was learning, I meant I have had 2 lessons on vbs. Just the basics.
              I think it's pointless in me trying to learn something I won't understand right now.
               
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • New Messages
                • No New Messages
                • Hot Topic w/ New Messages
                • Hot Topic w/o New Messages
                • Locked w/ New Messages
                • Locked w/o New Messages
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.9