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

Username:   Password: 
 RegisterRegister   
 Help! Arrays and loops
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanielChua




PostPosted: Tue Apr 05, 2016 7:52 pm   Post subject: Help! Arrays and loops

I'm relatively new to programming in Turing and I'm starting to learn it through my highschool ICS course. We are assigned to gather an unknown number of test scores (in percent) and to calculate the average of passing scores (75 and above). At the same time, I'm hoping to experiment with arrays and different types of loops. Below is what I have so far:

Turing:

var average : real := 0
var counter : int := 1
var numberOfQuizzes : int

put "How many quizzes are you marking? " ..
get numberOfQuizzes

var quizArray : flexible array 1 .. numberOfQuizzes of real

for i : 1 .. upper(quizArray)
    put "Quiz Score ", i , " " ..
    get quizArray(i)
end for

loop
    if quizArray(counter) < 75 then
        quizArray(counter) := upper(quizArray)
        new quizArray, upper(quizArray) - 1
    end if
    counter := counter + 1
    exit when counter >= numberOfQuizzes
end loop

for i : 1 .. upper(quizArray)
    average := average + quizArray(i)
end for

if upper(quizArray) >= 1 then
    put "The average of passing scores is ", average / upper(quizArray), "%"
else
    put "There were no passing scores :("
end if


The program works under most circumstances except when a non-passing score is collected or there are no passing scores. Any ideas or help wuld be greatly appreciated! Note: I'm using Turing version 4.1.1

Mod Edit: Syntax + whitepsace
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Tue Apr 05, 2016 10:00 pm   Post subject: Re: Help! Arrays and loops

Try checking what happens to your array when you find a value less than 75. What does the array look like before and after?
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  [ 2 Posts ]
Jump to:   


Style:  
Search: