2 Replies - 214 Views - Last Post: 29 November 2013 - 03:00 PM Rate Topic: -----

#1 Spartacus1982  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 13

Pseudocode - is this right

Posted 28 November 2013 - 04:42 PM

Have to do this in Pseudocode, is this correct for a file that should contain a students last name followed by their first name and one double representing average score. Question states each line in a file contains a students name, a space, students first name, a space, then 10 scores. Scores are separated by spaces.

START
DECLARE
File in,out,
String S, name,
int score, i, sum=0,
double average=0
END DECLARE
in=open("rawScores.txt") for read,
out=open("processedScores.txt") for write
READ S from in
While (S!="End")
Write S to out
Read score from in
Write score to out
End While
For i=1 to 10, step 1
sum=sum + score
write (sum) to out
End for
average=sum/10
Close in
Write name + answer to out
END

Is This A Good Question/Topic? 0
  • +

Replies To: Pseudocode - is this right

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 337
  • View blog
  • Posts: 730
  • Joined: 27-June 09

Re: Pseudocode - is this right

Posted 29 November 2013 - 10:58 AM

Does READ S from in read a whole line or just a word? Either way, you are a bit off. Assuming we are reading a word at a time

1) read last name
2) write last name
3) read first name
4) write first name
5) read score and add to sum
6) repeat step 5 nine more times
7) write average
8) write newline
9) set sum to 0
10) repeat 1 through 9 until end of in file
Was This Post Helpful? 0
  • +
  • -

#3 Spartacus1982  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 13

Re: Pseudocode - is this right

Posted 29 November 2013 - 03:00 PM

Thank you, I now have a better understand from your comment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1