Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing help.. This is the hardest thing :(
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
icexblood




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: 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?!
icexblood




PostPosted: 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
icexblood




PostPosted: 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
michaelp




PostPosted: 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
richcash




PostPosted: 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).
icexblood




PostPosted: 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
icexblood




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: 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
icexblood




PostPosted: 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
syntax_error




PostPosted: 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
icexblood




PostPosted: 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
syntax_error




PostPosted: 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
richcash




PostPosted: 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.
syntax_error




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 24 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: