Help needed in creation and order of algorithm.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    Originally posted by sslionheart
    becasue the values come first and then the calculations??
    Right, you need the vales to be able to make the calculation. Now what I believe kidfiction was saying is that there is a slight semantic error in what you posted. Variables in C/C++ are quite specific, so you need to make sure you have the exact same variable name for each part. (Hint: look at average - and look at kidfiction's post above)
    Last edited by sicarie; May 29 '07, 12:33 AM. Reason: kidfiction's help is probably better than mine ... :(

    Comment

    • sslionheart
      New Member
      • May 2007
      • 20

      #17
      Originally posted by kidfiction
      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.
      hmmm ok ya thats makes alot of sense... the way u said it so then it should looks more like this?

      Input gallonsOfGasUse d
      Input milesTraveled
      Milespergallon = milesTraveled / gallonsOfGasUse d
      print Milespergallon.


      i didnt even catch onto that print error

      Comment

      • kidfiction
        New Member
        • May 2007
        • 16

        #18
        Originally posted by sslionheart
        hmmm ok ya thats makes alot of sense... the way u said it so then it should looks more like this?

        Input gallonsOfGasUse d
        Input milesTraveled
        Milespergallon = milesTraveled / gallonsOfGasUse d
        print Milespergallon.


        i didnt even catch onto that print error
        Great job! that looks very correct to me. Have you attempted the second problem yet?

        Comment

        • sslionheart
          New Member
          • May 2007
          • 20

          #19
          :-) only cuz u guys walked me through it... i dunno what im gonna do when the test comes wensday

          the second question i have no clue about. i gues i should keep reading?

          also there is a 3rd question but how would you propose i go about it? typing the whole thing out? since i cannot link to a picture of it like last time

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #20
            Originally posted by sslionheart
            :-) only cuz u guys walked me through it... i dunno what im gonna do when the test comes wensday

            the second question i have no clue about. i gues i should keep reading?

            also there is a 3rd question but how would you propose i go about it? typing the whole thing out? since i cannot link to a picture of it like last time
            I'm sure you'll do fine on your test - it's just a matter of thinking steps out logically, and exactly. With every line ask yourself, do I have everything i need for this, and if I was going to do it by hand, would I do it in this order?

            The 2nd question - it tells you the types of those variables. All you need to do is go through and match the types. Do you know the different variable types that exist?

            If there is a third question, you need to approach it slowly, and ask questions about what you don't understand in the question. For instance, with the first one - "how do I differentiate between given types?" is a good question that you can ask us that will help you be able to answer it by yourself.

            Comment

            • kidfiction
              New Member
              • May 2007
              • 16

              #21
              I am sure it is in your reading but as I said before:

              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?

              Comment

              • sslionheart
                New Member
                • May 2007
                • 20

                #22
                i have no idea... how to do this second excersize.. its freaking me out

                ive read the full chapter

                this stuff really intimidates me

                first part is a. myAge = 23...

                so um i have no idea how to tell if that valid or not

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #23
                  Originally posted by sslionheart
                  i have no idea... how to do this second excersize.. its freaking me out

                  ive read the full chapter

                  this stuff really intimidates me

                  first part is a. myAge = 23...

                  so um i have no idea how to tell if that valid or not
                  Ok, so let's start with what is given. What type is 'myAge'?

                  Comment

                  • sslionheart
                    New Member
                    • May 2007
                    • 20

                    #24
                    numeric variable

                    is there a easier way for us to chat?

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #25
                      Originally posted by sslionheart
                      numeric variable
                      right - the more common name is 'int'
                      Originally posted by sslionheart
                      is there a easier way for us to chat?
                      Yeah, but then anyone else with the same problem won't be able to see what happened and learn from it.

                      Anyway, what is 23?
                      Last edited by sicarie; May 29 '07, 01:41 AM. Reason: Right, forgot the second part of the question...

                      Comment

                      • sslionheart
                        New Member
                        • May 2007
                        • 20

                        #26
                        i dont know what 23 is :-(

                        and if we do this through aim i can post the whole chat log... i juss need fast help and this is kinda slow

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #27
                          Originally posted by sslionheart
                          i dont know what 23 is :-(

                          and if we do this through aim i can post the whole chat log... i juss need fast help and this is kinda slow
                          Well, in this case, I would recommend studying the types - what they are, what they contain, etc...

                          23 is a number, right? So what type of data type can hold a number?

                          Comment

                          • sslionheart
                            New Member
                            • May 2007
                            • 20

                            #28
                            23 would be numeric would it?

                            so it would be a valid statement?

                            then b. myAge = youRate would also be valid right?

                            c. myAge = departmentCode is not valid? but why? i could be completly wrong

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #29
                              Originally posted by sslionheart
                              23 would be numeric would it?

                              so it would be a valid statement?

                              then b. myAge = youRate would also be valid right?

                              c. myAge = departmentCode is not valid? but why? i could be completly wrong
                              What type is departmentCode? Does it match the type of myAge?

                              One of the things I would recommend that would help is to put this into a compiler. You can do these associations, and then print them out - see if they're the proper value, or see error messages on specific lines and figure out what they are.

                              Comment

                              • sslionheart
                                New Member
                                • May 2007
                                • 20

                                #30
                                Originally posted by sicarie
                                What type is departmentCode? Does it match the type of myAge?

                                One of the things I would recommend that would help is to put this into a compiler. You can do these associations, and then print them out - see if they're the proper value, or see error messages on specific lines and figure out what they are.
                                where can i get a compiler?

                                and no they do not match so thats what makes it not valid?

                                Comment

                                Working...