By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 455,513 Members | 1,629 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

# Help needed in creation and order of algorithm.

 P: 20 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 May 28 '07 #1
Share this Question
39 Replies

 P: 16 I dont see what the question here is... May 28 '07 #2

 P: 20 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 gallonsOfGasUsed gallonsOfGasUsed / milesTravelled = milesPerGallon print milesPerGal now like i said i suck at this but what i did was Milespergallon = gallonsOfGasUsed / milesTraveled Input gallonsOfGasUsed 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 May 28 '07 #3

 Expert Mod 2.5K+ P: 4,677 what i did was Milespergallon = gallonsOfGasUsed / milesTraveled Input gallonsOfGasUsed 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. here is my next question http://i33.photobucket.com/albums/d6...t/IMG00141.jpg 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. May 28 '07 #4

 P: 16 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 gallonsOfGasUsed gallonsOfGasUsed / milesTravelled = milesPerGallon print milesPerGal now like i said i suck at this but what i did was Milespergallon = gallonsOfGasUsed / milesTraveled Input gallonsOfGasUsed 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. May 28 '07 #5

 P: 20 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 May 28 '07 #6

 Expert Mod 2.5K+ P: 4,677 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. 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? May 28 '07 #7

 P: 16 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. May 29 '07 #8

 Expert Mod 2.5K+ P: 4,677 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. May 29 '07 #9

 P: 20 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. May 29 '07 #10

 Expert Mod 2.5K+ P: 4,677 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.) 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. 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. May 29 '07 #11

 P: 20 Input gallonsOfGasUsed Input milesTraveled Milespergallon = gallonsOfGasUsed / milesTraveled Print average is that how the first one should look? May 29 '07 #12

 Expert Mod 2.5K+ P: 4,677 Input gallonsOfGasUsed Input milesTraveled Milespergallon = gallonsOfGasUsed / 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? May 29 '07 #13

 P: 20 Well, can you justify to me (or to your professor) why that is correct? becasue the values come first and then the calculations?? May 29 '07 #14

 P: 16 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 gallonsOfGasUsed / milesTravelled = milesPerGallon into Milespergallon = gallonsOfGasUsed / 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 = gallonsOfGasUsed / milesTraveled Input gallonsOfGasUsed Input milesTraveled Print average your first step is to assign Milespergallon, but to what?! We dont know what gallonsOfGasUsed 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. May 29 '07 #15

 Expert Mod 2.5K+ P: 4,677 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) May 29 '07 #16

 P: 20 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 gallonsOfGasUsed / milesTravelled = milesPerGallon into Milespergallon = gallonsOfGasUsed / 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 = gallonsOfGasUsed / milesTraveled Input gallonsOfGasUsed Input milesTraveled Print average your first step is to assign Milespergallon, but to what?! We dont know what gallonsOfGasUsed 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 gallonsOfGasUsed Input milesTraveled Milespergallon = milesTraveled / gallonsOfGasUsed print Milespergallon. i didnt even catch onto that print error May 29 '07 #17

 P: 16 hmmm ok ya thats makes alot of sense... the way u said it so then it should looks more like this? Input gallonsOfGasUsed Input milesTraveled Milespergallon = milesTraveled / gallonsOfGasUsed 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? May 29 '07 #18

 P: 20 :-) 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 May 29 '07 #19

 Expert Mod 2.5K+ P: 4,677 :-) 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. May 29 '07 #20

 P: 16 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? May 29 '07 #21

 P: 20 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 May 29 '07 #22

 Expert Mod 2.5K+ P: 4,677 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'? May 29 '07 #23

 P: 20 numeric variable is there a easier way for us to chat? May 29 '07 #24

 Expert Mod 2.5K+ P: 4,677 numeric variable right - the more common name is 'int' 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? May 29 '07 #25

 P: 20 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 May 29 '07 #26

 Expert Mod 2.5K+ P: 4,677 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? May 29 '07 #27

 P: 20 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 May 29 '07 #28

 Expert Mod 2.5K+ P: 4,677 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. May 29 '07 #29

 P: 20 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? May 29 '07 #30

 Expert Mod 2.5K+ P: 4,677 where can i get a compiler? and no they do not match so thats what makes it not valid? There are a few different places - it's just a matter of which one you are most comfortable with. I personally like GCC but I'm a Linux guy. Some people like the Bloodshed compiler, I've seen Turbo C++ around, and there is always Visual C++. Yep, the types are invalid - an integer type cannot hold a character type. May 29 '07 #31

 P: 20 myAge = "departmentCode" so this would be valid correct? May 29 '07 #32

 Expert Mod 2.5K+ P: 4,677 myAge = "departmentCode" so this would be valid correct? Nope - this is another issue. By putting it in quotes, you're saying 'the letters that make up the string departmentCode,' so these are characters as well. May 29 '07 #33

 P: 20 so its not valid for the same reason as without quotations? ok now e says 42=myAge is that not valid becuase myAge needs to be on the other side? May 29 '07 #34

 Expert Mod 2.5K+ P: 4,677 so its not valid for the same reason as without quotations? ok now e says 42=myAge is that not valid becuase myAge needs to be on the other side? Right, because the association is to the left (whatever is on the left will take on the value of what is on the right). May 29 '07 #35

 P: 20 f. yourRate = 3.5 valid? g. yourRate= myAge valid? h. yourRate = departmentCode not valid because an integer type cannot hold a character type? May 29 '07 #36

 Expert Mod 2.5K+ P: 4,677 f. yourRate = 3.5 valid? g. yourRate= myAge valid? h. yourRate = departmentCode not valid because an integer type cannot hold a character type? Ha, this is your homework, but you are doing well so far ;). Read up on 'double' type as well. If there is one you're confused about, put it in the compiler - it will spit out the answer right away, then you just have to figure out why. If you're still confused, post the line you tried, and the error. May 29 '07 #37

 P: 20 im installing visual c++ right now hopefully i can figure out how to use it! May 29 '07 #38

 P: 20 um it is not working with windows vista... May 29 '07 #39

 P: 20 i got it working but where do i go in the program to test them? May 29 '07 #40

### Post your reply

Sign in to post your reply or Sign up for a free account.