Help needed in creation and order of algorithm.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sslionheart
    New Member
    • May 2007
    • 20

    Help needed in creation and order of algorithm.

    i have homework due tomorrow and i really need some help so how would i go about it?

    post my questions here or could someone message me?

    removed per posting guidelines
    Last edited by sicarie; May 28 '07, 11:38 PM. Reason: Contact info removed per posting guidelines
  • kidfiction
    New Member
    • May 2007
    • 16

    #2
    I dont see what the question here is...

    Comment

    • sslionheart
      New Member
      • May 2007
      • 20

      #3
      well i have a few questions... and im trying to re read chapter one but it doesnt help much..

      1st question is This pseudocode segment is intended to describe computing the number of miles per gallon you get with your automobile. and it wants you to find the errors and re arrange it etc...

      input milesTraveled
      input gallonsOfGasUse d
      gallonsOfGasUse d / milesTravelled = milesPerGallon
      print milesPerGal

      now like i said i suck at this but what i did was

      Milespergallon = gallonsOfGasUse d / milesTraveled
      Input gallonsOfGasUse d
      Input milesTraveled
      Print average

      and i doubt i got it right

      here is my next question

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by sslionheart
        what i did was

        Milespergallon = gallonsOfGasUse d / milesTraveled
        Input gallonsOfGasUse d
        Input milesTraveled
        Print average
        After reading it - why did you change anything? It looks like you 1) get the first variable, 2) get the second variable 3) make the calculation using the variables and then 4) print the result. They were good in the order they started in.
        Originally posted by sslionheart
        What have you tried on this?

        Also, please take a look at our Posting Guidelines, especially the parts about posting what you tried (like on your second problem), and using a title that accurately describes your issue. I have changed your thread title, please let me know if you think it should be different/something else.
        Last edited by sicarie; May 28 '07, 11:42 PM. Reason: Re-read the first part, and gave link.

        Comment

        • kidfiction
          New Member
          • May 2007
          • 16

          #5
          Originally posted by sslionheart
          well i have a few questions... and im trying to re read chapter one but it doesnt help much..

          1st question is This pseudocode segment is intended to describe computing the number of miles per gallon you get with your automobile. and it wants you to find the errors and re arrange it etc...

          input milesTraveled
          input gallonsOfGasUse d
          gallonsOfGasUse d / milesTravelled = milesPerGallon
          print milesPerGal

          now like i said i suck at this but what i did was

          Milespergallon = gallonsOfGasUse d / milesTraveled
          Input gallonsOfGasUse d
          Input milesTraveled
          Print average

          and i doubt i got it right

          here is my next question
          http://i33.photobucket.com/albums/d6...t/IMG00141.jpg
          When doing the first question, ask yourself:
          can I use a variable before its inputted?
          can I print a variable that i haven't initialized?

          With the second question you need to ask yourself for each portion:
          What is the syntax for assigning a variable?
          What is the syntax for assigning a variable that is a number?
          What is the syntax for assigning a variable that is a character array or string?
          Can I assign a number to a string variable?
          Can I assign a string to a number variable?

          Hope this helps.

          Comment

          • sslionheart
            New Member
            • May 2007
            • 20

            #6
            ok so i did the first one wrong? the order was fine you say?

            well a friend in class told me that = always goes first and that is why i rearranged that..

            and sorry if i violated your rules.. and the topic title is fine

            im still so confused.. i need it all explained to me.. ive never done any of this

            is it possible for anyone to message me on contact info removed per posting guidelines
            Last edited by sicarie; May 28 '07, 11:56 PM. Reason: Contact info removed per posting guidelines

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              Originally posted by sslionheart
              ok so i did the first one wrong? the order was fine you say?

              well a friend in class told me that = always goes first and that is why i rearranged that..
              In pseudocode it doesn't matter - but in the program it would. I was speaking more to the general statement, and it's placement in relation to the others. That's what pseudocode is - just a description of how you could do it using pen and paper if you had to. Then you convert it to code.
              Originally posted by sslionheart
              and sorry if i violated your rules..
              Then please read why you did it - you just did it again.

              Are you confused as to why the first one is correct? If so, read through my post #4 again - I explain it in order of steps to complete - that's the pseudocode for the program.

              Also, what do you have on the second?

              Comment

              • kidfiction
                New Member
                • May 2007
                • 16

                #8
                Originally posted by sicarie
                I

                Are you confused as to why the first one is correct? If so, read through my post #4 again - I explain it in order of steps to complete - that's the pseudocode for the program.

                While this is pseudo-code, I do see a few errors in it, especially after looking at the second question. The first is on the second to last line and the second error is on the last line. The second error could simply be a copy error however.

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #9
                  Originally posted by kidfiction
                  While this is pseudo-code, I do see a few errors in it, especially after looking at the second question. The first is on the second to last line and the second error is on the last line. The second error could simply be a copy error however.
                  Honestly, I didn't follow the OP's link - my posts were based on the information he provided because he set them up as separate questions, I was dealing with the first before I dealt with the second. If there is a mistake - especially in the direction I have guided him - please post whatever help you can.

                  Comment

                  • sslionheart
                    New Member
                    • May 2007
                    • 20

                    #10
                    Originally posted by sicarie
                    In pseudocode it doesn't matter - but in the program it would. I was speaking more to the general statement, and it's placement in relation to the others. That's what pseudocode is - just a description of how you could do it using pen and paper if you had to. Then you convert it to code.

                    Then please read why you did it - you just did it again.

                    Are you confused as to why the first one is correct? If so, read through my post #4 again - I explain it in order of steps to complete - that's the pseudocode for the program.

                    Also, what do you have on the second?
                    i am generally confused all the way around

                    i have not made any progress on the second question as i am re reading chapter one and hoping for someone to give me one on one help. no i do not want the answers as i really want to learn this fluently.

                    i did skim through your rules but i do not have time to read them all as i have alot of homework to complete by tomorrow morning.

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #11
                      Originally posted by sslionheart
                      i am generally confused all the way around
                      Ok, well, the first step is to pick one thing. You're still confused about the pseudocode - can you post the whole assignment? (as per kidfiction, I want to make sure I'm not leading you in the wrong direction.)
                      Originally posted by sslionheart
                      i have not made any progress on the second question as i am re reading chapter one and hoping for someone to give me one on one help. no i do not want the answers as i really want to learn this fluently.
                      We'll get to 2 as soon as we're clear on 1 - it's just a matter of identifying the different types and making sure they match on both sides.
                      Originally posted by sslionheart
                      i did skim through your rules but i do not have time to read them all as i have alot of homework to complete by tomorrow morning.
                      Yeah, there are also notes at the bottom of your posts, and if you re-read them you'll see what was removed.

                      Comment

                      • sslionheart
                        New Member
                        • May 2007
                        • 20

                        #12
                        Input gallonsOfGasUse d
                        Input milesTraveled
                        Milespergallon = gallonsOfGasUse d / milesTraveled
                        Print average

                        is that how the first one should look?

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #13
                          Originally posted by sslionheart
                          Input gallonsOfGasUse d
                          Input milesTraveled
                          Milespergallon = gallonsOfGasUse d / milesTraveled
                          Print average

                          is that how the first one should look?
                          Well, can you justify to me (or to your professor) why that is correct?

                          Comment

                          • sslionheart
                            New Member
                            • May 2007
                            • 20

                            #14
                            Originally posted by sicarie
                            Well, can you justify to me (or to your professor) why that is correct?
                            becasue the values come first and then the calculations??

                            Comment

                            • kidfiction
                              New Member
                              • May 2007
                              • 16

                              #15
                              Originally posted by sslionheart
                              i am generally confused all the way around

                              i have not made any progress on the second question as i am re reading chapter one and hoping for someone to give me one on one help. no i do not want the answers as i really want to learn this fluently.

                              i did skim through your rules but i do not have time to read them all as i have alot of homework to complete by tomorrow morning.
                              Perhaps this will help:
                              In order to assign variable1 as variable2 we would write

                              variable1 = variable2

                              Make note that variable1 is on the left side, meaning that variable1 now is equal to whatever variable2 is. If we wrote instead

                              variable2 = variable1

                              then variable2 would be equal to whatever variable1 is. When you changed
                              gallonsOfGasUse d / milesTravelled = milesPerGallon
                              into
                              Milespergallon = gallonsOfGasUse d / milesTraveled

                              you were correct in that it would not throw a syntax error because we now have Milespergallon on the left hand side which is what we want. But if you look carefully, what does the right have side say? I see gallonsOfGasUsed/milesTraveled. Do you see the error?

                              Now lets go step by step with what you came up with:

                              Milespergallon = gallonsOfGasUse d / milesTraveled
                              Input gallonsOfGasUse d
                              Input milesTraveled
                              Print average

                              your first step is to assign Milespergallon, but to what?! We dont know what gallonsOfGasUse d or milesTraveled is equal to. We have to know what they are equal to before we can use them, so we should probably input them before we do anything. Ok, now we're going to print it, we want to print our miles per gallon, but you're saying print average. What is average equal to? I dont know, do you know? The program surely doesnt know. So if we want to print Milespergallong then we would say

                              print Milespergallon.


                              hope this helps for problem 1.

                              Comment

                              Working...