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

Username:   Password: 
 RegisterRegister   
 subprogram question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mo




PostPosted: Sat Jan 26, 2008 6:44 pm   Post subject: subprogram question

can anybody help me create a Turing program that accepts exactly 15 student?s marks in (as a percent) and outputs only those marks that are equal to or above the average (mean) mark. and the input is coming from a file named (in.txt) say the mean is 75 %
Sponsor
Sponsor
Sponsor
sponsor
isaiahk9




PostPosted: Mon May 05, 2008 5:40 pm   Post subject: Re: subprogram question

I can help you with everything besides the text file. This probably is not the most effective code :
var mark1 : int
var mark2 : int
var mark3 : int
var mark4 : int
var mark5 : int

var mark6 : int
var mark7 : int
var mark8 : int
var mark9 : int
var mark10 : int

var mark11 : int
var mark12 : int
var mark13 : int
var mark14 : int
var mark15 : int

var total : int := 0
var average : int

put "Input your percent for mark 1 : "
get mark1
total := total + mark1

put "Input your percent for mark 2 : "
get mark2
total := total + mark2

put "Input your percent for mark 3 : "
get mark3
total := total + mark3

put "Input your percent for mark 4 : "
get mark4
total := total + mark4

put "Input your percent for mark 5 : "
get mark5
total := total + mark5

put "Input your percent for mark 6 : "
get mark6
total := total + mark6

put "Input your percent for mark 7 : "
get mark7
total := total + mark7

put "Input your percent for mark 8 : "
get mark8
total := total + mark8

put "Input your percent for mark 9 : "
get mark9
total := total + mark9

put "Input your percent for mark 10 : "
get mark10
total := total + mark10

put "Input your percent for mark 11 : "
get mark11
total := total + mark11

put "Input your percent for mark 12 : "
get mark12
total := total + mark12

put "Input your percent for mark 13 : "
get mark13
total := total + mark13

put "Input your percent for mark 14 : "
get mark14
total := total + mark14

put "Input your percent for mark 15 : "
get mark15
total := total + mark15

put "The average was ", total/15, "."
average := total div 15
put "The marks over the average :"
if mark1 > average then
put "mark 1 - ",mark1, " "
else
end if

if mark2 > average then
put "mark 2 - ", mark2, " "
else
end if

if mark3 > average then
put "mark 3 - ",mark3, " "
else
end if

if mark4 > average then
put "mark 4 - ",mark4, " "
else
end if

if mark5 > average then
put "mark 5 - ",mark5, " "
else
end if

if mark6 > average then
put "mark 6 - ",mark6, " "
else
end if

if mark7 > average then
put "mark 7 - ",mark7, " "
else
end if

if mark8 > average then
put "mark 8 - ",mark8, " "
else
end if

if mark9 > average then
put "mark 9 - ",mark9, " "
else
end if

if mark10 > average then
put "mark 10 - ",mark10, " "
else
end if

if mark11 > average then
put "mark 11 - ",mark11, " "
else
end if

if mark12 > average then
put "mark 12 - ",mark12, " "
else
end if

if mark13 > average then
put "mark 13 - ",mark13, " "
else
end if

if mark14 > average then
put "mark 14 - ",mark14, " "
else
end if

if mark15 > average then
put "mark 15 - ",mark15, " "
else
end if


Wow! Didn't think it would take me 165 lines. oh well. Hope this helps.
Mackie




PostPosted: Mon May 05, 2008 5:56 pm   Post subject: RE:subprogram question

That is probably the least efficient way you could have done it.
Tony




PostPosted: Mon May 05, 2008 5:59 pm   Post subject: RE:subprogram question

It is normally against the forum rules to post full solutions... though this isn't really full. And it's more for the benefit of isaiahk9 than original poster.

Turing:

var marks : array 1..15 of int
var total : int := 0

for i: 1..15
   put "Input your percent for mark ", i, " : "
   get marks(i)
   total += marks(i)
end for

put "The average was ", total/15, "."

for i: 1..15
   if marks(i) > (total/15)
   put "mark ", i, " - ", marks(i)
end for


The above code is functionally identical to yours. Study it well.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
isaiahk9




PostPosted: Fri May 09, 2008 3:19 pm   Post subject: RE:subprogram question

k, sorry about posting code. I see, using the i variable to keep track of each mark in an array. Didn't think of that.
Tony




PostPosted: Fri May 09, 2008 3:24 pm   Post subject: RE:subprogram question

well no, it's good that you posted that code, because now you got to learn something new Smile
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 1  [ 6 Posts ]
Jump to:   


Style:  
Search: