Originally posted by sslionheart
Help needed in creation and order of algorithm.
Collapse
X
-
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 ... :( -
hmmm ok ya thats makes alot of sense... the way u said it so then it should looks more like this?Originally posted by kidfictionPerhaps 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.
Input gallonsOfGasUse d
Input milesTraveled
Milespergallon = milesTraveled / gallonsOfGasUse d
print Milespergallon.
i didnt even catch onto that print errorComment
-
Great job! that looks very correct to me. Have you attempted the second problem yet?Originally posted by sslionhearthmmm 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 errorComment
-
:-) 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 timeComment
-
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?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
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
-
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
-
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 notComment
-
Ok, so let's start with what is given. What type is 'myAge'?Originally posted by sslionhearti 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 notComment
-
-
right - the more common name is 'int'Originally posted by sslionheartnumeric variable
Yeah, but then anyone else with the same problem won't be able to see what happened and learn from it.Originally posted by sslionheartis there a easier way for us to chat?
Anyway, what is 23?Last edited by sicarie; May 29 '07, 01:41 AM. Reason: Right, forgot the second part of the question...Comment
-
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 slowComment
-
Well, in this case, I would recommend studying the types - what they are, what they contain, etc...Originally posted by sslionhearti 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
23 is a number, right? So what type of data type can hold a number?Comment
-
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 wrongComment
-
What type is departmentCode? Does it match the type of myAge?Originally posted by sslionheart23 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
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
-
where can i get a compiler?Originally posted by sicarieWhat 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.
and no they do not match so thats what makes it not valid?Comment
Comment