Computer Science Canada

Turing help.. This is the hardest thing :(

Author:  icexblood [ Mon Mar 03, 2008 6:59 pm ]
Post subject:  Turing help.. This is the hardest thing :(

Ok im trying to make this program and im a nubie
it asks for how much marks you want to enter from 4-6, then averages them

var marks: real
marks:= 0
loop
put "What are the marks you want to enter? Type stop to exit."
get marks
exit when marks = "exit"
end loop

thats what i got so far Sad

Author:  syntax_error [ Mon Mar 03, 2008 7:05 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

use an array to hold the marks. go to the Turing Walkthrough; learn from that ask more questions if you have. and please use code tags?!

Author:  icexblood [ Mon Mar 03, 2008 7:15 pm ]
Post subject:  Re: RE:Turing help.. This is the hardest thing :(

syntax_error @ Mon Mar 03, 2008 7:05 pm wrote:
use an array to hold the marks. go to the Turing Walkthrough; learn from that ask more questions if you have. and please use code tags?!
ok i never learned and this i cant cos i need it now T_T

Author:  icexblood [ Mon Mar 03, 2008 7:18 pm ]
Post subject:  Re: RE:Turing help.. This is the hardest thing :(

icexblood @ Mon Mar 03, 2008 7:15 pm wrote:
syntax_error @ Mon Mar 03, 2008 7:05 pm wrote:
use an array to hold the marks. go to the Turing Walkthrough; learn from that ask more questions if you have. and please use code tags?!
ok i never learned and this i cant cos i need it now T_T
This is my new one

var marks : int
var count : int
marks := 0
count := 0
loop
put "What are the marks you want to enter? Type stop to exit."
get marks
marks := marks + marks
exit when marks := "done"
count := count + 1
end loop
put "The average mark is " marks / count

Author:  michaelp [ Mon Mar 03, 2008 7:33 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

Did you even test that code?
I don't know why I asked that, because I know you didn't. Because I just did, and it didn't work. You said "exit when marks := "done"
There are 2 things wrong with that line:

1. ':=' is the assignment operator. So your exit statement assigns marks to "done"
2. marks is an integer value. It won't run like that, and there will be an error if you try to enter it.

Download Turing and test it yourself next time.
http://holtsoft.com/Turing%204.1.1.zip

Author:  richcash [ Mon Mar 03, 2008 7:34 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

code:
get marks
marks := marks + marks

What does that do? In your head try putting numbers in for marks and calculate what will happen. Do you see the problem? You need another variable.

code:
exit when marks := "done"

marks is an integer. How can it ever be a string? Maybe you should tell the user to enter -1 to end inputting (unless you want to convert types).

Author:  icexblood [ Mon Mar 03, 2008 7:39 pm ]
Post subject:  Re: RE:Turing help.. This is the hardest thing :(

michaelp @ Mon Mar 03, 2008 7:33 pm wrote:
Did you even test that code?
I don't know why I asked that, because I know you didn't. Because I just did, and it didn't work. You said "exit when marks := "done"
There are 2 things wrong with that line:

1. ':=' is the assignment operator. So your exit statement assigns marks to "done"
2. marks is an integer value. It won't run like that, and there will be an error if you try to enter it.

Download Turing and test it yourself next time.
http://holtsoft.com/Turing%204.1.1.zip

uhh i tested my new one that im working on.. Look, only 1 thing is wrong and its somethin g to do with boolean o_O
var markstotal : real
var marks1 : real
var marks2 : real
var marks3 : real
var marks4 : real
var marks5 : real
var marks6 : real
var count : int
marks1 := 0
marks2 := 0
marks3 := 0
marks4 := 0
marks5 := 0
marks6 := 0
count := 0
loop
put "What are the 1st marks you want to enter? Type done to exit."
get marks1
put "What are the 2nd marks you want to enter? Type done to exit."
get marks2
put "What are the 3rd marks you want to enter? Type done to exit."
get marks3
put "What are the 4th marks you want to enter? Type done to exit."
get marks4
put "What are the 5th marks you want to enter? Type done to exit."
get marks5
put "What are the 6th marks you want to enter? Type done to exit."
get marks6
exit when marks1, marks2, marks3, marks4, marks5, mark6 = "done"
markstotal := marks1 + marks2 + marks3 + marks4 + marks5 + marks6
count := count + 1
end loop
put "The average mark is ", markstotal / count

Author:  icexblood [ Mon Mar 03, 2008 7:42 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

richcash @ Mon Mar 03, 2008 7:34 pm wrote:
code:
get marks
marks := marks + marks

What does that do? In your head try putting numbers in for marks and calculate what will happen. Do you see the problem? You need another variable.

code:
exit when marks := "done"

marks is an integer. How can it ever be a string? Maybe you should tell the user to enter -1 to end inputting (unless you want to convert types).

ok look, this is new one
theres 1 error saying something about a boolean

var markstotal : real
var marks1 : real
var marks2 : real
var marks3 : real
var marks4 : real
var marks5 : real
var marks6 : real
var count : int
marks1 := 0
marks2 := 0
marks3 := 0
marks4 := 0
marks5 := 0
marks6 := 0
count := 0
loop
put "What are the 1st marks you want to enter? Type done to exit."
get marks1
put "What are the 2nd marks you want to enter? Type done to exit."
get marks2
put "What are the 3rd marks you want to enter? Type done to exit."
get marks3
put "What are the 4th marks you want to enter? Type done to exit."
get marks4
put "What are the 5th marks you want to enter? Type done to exit."
get marks5
put "What are the 6th marks you want to enter? Type done to exit."
get marks6
exit when marks1, marks2, marks3, marks4, marks5, mark6 = "done"
markstotal := marks1 + marks2 + marks3 + marks4 + marks5 + marks6
count := count + 1
end loop
put "The average mark is ", markstotal / count

Author:  syntax_error [ Mon Mar 03, 2008 7:43 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

that is because the "=" makes it a boolean expression and you cant compare ints with a string without casting.

honestly you dont even need the loop

Author:  icexblood [ Mon Mar 03, 2008 7:49 pm ]
Post subject:  Re: RE:Turing help.. This is the hardest thing :(

syntax_error @ Mon Mar 03, 2008 7:43 pm wrote:
that is because the "=" makes it a boolean expression and you cant compare ints with a string without casting.

honestly you dont even need the loop
soooo how can i modify the one i have right now Sad

Author:  syntax_error [ Mon Mar 03, 2008 8:05 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

jsut remove teh loop.

Turing:


var markstotal : real
var marks1 : real
var marks2 : real
var marks3 : real
var marks4 : real
var marks5 : real
var marks6 : real
var count : int
marks1 := 0
marks2 := 0
marks3 := 0
marks4 := 0
marks5 := 0
marks6 := 0


put "What are the 1st marks you want to enter? Type done to exit."
get marks1
put "What are the 2nd marks you want to enter? Type done to exit."
get marks2
put "What are the 3rd marks you want to enter? Type done to exit."
get marks3
put "What are the 4th marks you want to enter? Type done to exit."
get marks4
put "What are the 5th marks you want to enter? Type done to exit."
get marks5
put "What are the 6th marks you want to enter? Type done to exit."
get marks6

markstotal := marks1 + marks2 + marks3 + marks4 + marks5 + marks6

put "The average mark is ", markstotal / count

Author:  icexblood [ Mon Mar 03, 2008 8:19 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

syntax_error @ Mon Mar 03, 2008 8:05 pm wrote:
jsut remove teh loop.

Turing:


var markstotal : real
var marks1 : real
var marks2 : real
var marks3 : real
var marks4 : real
var marks5 : real
var marks6 : real
var count : int
marks1 := 0
marks2 := 0
marks3 := 0
marks4 := 0
marks5 := 0
marks6 := 0


put "What are the 1st marks you want to enter? Type done to exit."
get marks1
put "What are the 2nd marks you want to enter? Type done to exit."
get marks2
put "What are the 3rd marks you want to enter? Type done to exit."
get marks3
put "What are the 4th marks you want to enter? Type done to exit."
get marks4
put "What are the 5th marks you want to enter? Type done to exit."
get marks5
put "What are the 6th marks you want to enter? Type done to exit."
get marks6

markstotal := marks1 + marks2 + marks3 + marks4 + marks5 + marks6

put "The average mark is ", markstotal / count

not as good as ur old one man, that one rox

Author:  syntax_error [ Mon Mar 03, 2008 8:23 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

ya well, nor array so cant do much =P

Author:  richcash [ Mon Mar 03, 2008 8:38 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

What? Don't do that! Don't you want the user to be able to enter as many values as they want?

You only need one variable for the input. You can use that variable over and over to get the input, and then add it to a separate variable to keep track of the sum each time. That is all that was wrong with the second program you posted in this thread (and the int/string issue). You just needed a separate variable for the sum.

Author:  syntax_error [ Mon Mar 03, 2008 9:14 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

richcash I did try to make icexblood use array but he hasnt done that in class yet thus he didnt wish to.

an old saying: you can only lead a horse to the water, but you cannot force it to drink.

edit: w00t a NewBe Hacker now =P

Author:  HeavenAgain [ Mon Mar 03, 2008 9:20 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

syntax_error you can do it with array, BUT its not even necessary here (unless you going to use a certain mark that was entered sometimes later in your code)

and therefore
richcash @ Mon Mar 03, 2008 8:38 pm wrote:
You only need one variable for the input. You can use that variable over and over to get the input, and then add it to a separate variable to keep track of the sum each time.

Author:  syntax_error [ Mon Mar 03, 2008 9:43 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

oo yes that makes sense as well; Embarassed

my mistake.

Author:  DaveAngus [ Tue Mar 18, 2008 10:31 am ]
Post subject:  RE:Turing help.. This is the hardest thing :(

Here is a very simple way to do that average calculator.

There are shorter ways but if you are a newbie,
its easier to see everything nicely laid out.


This code will work very well for that.






/*
Name : Dave Angus
Date : Feb 21st 2008
Title: assi2.t
Description : This is a calculator that calculates your average.
*/

var per1 : int
var per2 : int
var per3 : int
var per4 : int
var average : real


/*
This is where the user can enter their marks.
*/


put "Please insert your four semester I marks to recieve your average"

put " Period One Mark:"
get per1

put " Period Two Mark:"
get per2

put " Period Three Mark:"
get per3

put " Period Four Mark:"
get per4

/* This 'cls' means clear screen if you havent been taught that yet.
*/
cls


put "Your average is: ", (per1 + per2 + per3 + per4) / 4
average := (per1 + per2 + per3 + per4) / 4

/*This is the output comment
I dont know if you have learnt if statements yet. If you havent, I can easily walk you though them.
They are very self explanitory.

*/

if average = 100 then
put "Your a genious!"

elsif average >= 90 then
put "Your next to flawless!!!"

elsif average >= 80 then
put "Great mark!"

elsif average >= 70 then
put "Push a little harder if you want honor role!"

elsif average >= 60 then
put "Good work."

elsif average >= 50 then
put "You almost failed!"

elsif average <= 50 then
put "You failed!"

end if

/*above is what you would use to ask/input the mark. I will then take that mark
and output a letter grade average*/





Let me know if you decide to use it

Author:  A.J [ Tue Mar 18, 2008 1:11 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

icexblood....u don't need an array!!!
just ask the user how many marks they want to input (store it in var numofmarks:int)
then make a variable 'total' that keeps adding on the mark (var total:=0) and a variable 'mark' to get each input (var mark:int)
then make a 'for' loop from 1 to numofmarks and keep getting 'mark' and add it on to 'total'
the average should then be total/numofmarks !!!!!!!!!

Author:  Carey [ Wed Mar 19, 2008 2:59 pm ]
Post subject:  RE:Turing help.. This is the hardest thing :(

OK, heres the simple explanation. you DO NOT need an array. all you do is ask the user for the number of marks they want to enter [call it n for now]. you then use a for loop (if you don't know what that is, check the Turing Walkthrough) to ask the user the marks n times. also (inside the for loop) add the entered marks to a running total. at the end, if you recall an average is all elements divided by how many elements there are. so you would output the running total divided by n and that will give you the answer.


EDIT: sorry to repeat you AJ, i used the quickreply thing of the first page and didnt notice that there was a second page. My bad. Oh well, maybe with two explanations he/she'll get it.

Author:  Xion [ Fri Mar 21, 2008 8:23 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

Quote:
Ok im trying to make this program and im a nubie
it asks for how much marks you want to enter from 4-6, then averages them

var marks: real
marks:= 0
loop
put "What are the marks you want to enter? Type stop to exit."
get marks
exit when marks = "exit"
end loop


Firstly, why do you guys post the absurdly long codings? He had the right Idea with a loop, just wasn't using it right.

Here is a simple solution:

code:

var marks : int
var sum : int :=0
var count :int :=0

put "Enter from 4 to 6 marks, when finished, type 0."
put ""
loop
put "Enter Mark"
get marks
put ""
exit when marks = 0
sum := sum + marks
count:= count + 1

end loop


put "The avereage of all your marks is ", sum / count


Granted it will add many more than 6 if the user imputs the values, if they yeild to the notice, this program is perfect.

Author:  jinjin [ Sat Mar 22, 2008 2:12 am ]
Post subject:  Re: Turing help.. This is the hardest thing :(

Quote:
Granted it will add many more than 6 if the user imputs the values, if they yeild to the notice, this program is perfect.


Alternatively, it could ask the user how many marks he/she wants to input before the loop, store it in a var, and the 'exit when' statement could correspond to that var. Also, if a mark was inputted ouside the 4-6 range, then there could be a seperate 'exit when' and/or 'if' statement for that.

Author:  TheGuyWhoGotOn [ Sat Mar 22, 2008 7:19 am ]
Post subject:  Re: Turing help.. This is the hardest thing :(

Xion @ Fri Mar 21, 2008 8:23 pm wrote:
Quote:
Ok im trying to make this program and im a nubie
it asks for how much marks you want to enter from 4-6, then averages them

var marks: real
marks:= 0
loop
put "What are the marks you want to enter? Type stop to exit."
get marks
exit when marks = "exit"
end loop


Firstly, why do you guys post the absurdly long codings? He had the right Idea with a loop, just wasn't using it right.

Here is a simple solution:

code:

var marks : int
var sum : int :=0
var count :int :=0

put "Enter from 4 to 6 marks, when finished, type 0."
put ""
loop
put "Enter Mark"
get marks
put ""
exit when marks = 0
sum := sum + marks
count:= count + 1

end loop


put "The avereage of all your marks is ", sum / count


Granted it will add many more than 6 if the user imputs the values, if they yeild to the notice, this program is perfect.


Xion has a great idea for beginners because it's very easy to read...Unless somebody has a better idea I think we have a solution ^_^. The only thing I would change is in "put """ I would use "put skip", I don't know if it's any faster though.

jinjin @ Sat Mar 22, 2008 2:12 am wrote:
Quote:
Granted it will add many more than 6 if the user imputs the values, if they yeild to the notice, this program is perfect.


Alternatively, it could ask the user how many marks he/she wants to input before the loop, store it in a var, and the 'exit when' statement could correspond to that var. Also, if a mark was inputted ouside the 4-6 range, then there could be a seperate 'exit when' and/or 'if' statement for that.


That would work too but it's already supposed to exit when it finds a zero (mentioned in the first post) so there is no point really.

Author:  Xion [ Sat Mar 22, 2008 6:57 pm ]
Post subject:  Re: Turing help.. This is the hardest thing :(

Thank you "TheGuyWhoGotOn" =D I think my coding is easy for beginners because I just started this class this semester lol (January) So I only know the basics of coding Smile

Muahahahaaha, So proud I figured that out myself!!

& I just put in the put ""'s to make the output on the screen more attractive and easier for the user to read.


: