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

Username:   Password: 
 RegisterRegister   
 Can anyone make suggestions to make this program better?
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PR069




PostPosted: Thu Oct 09, 2014 6:31 pm   Post subject: Can anyone make suggestions to make this program better?

Turing:

%Average for one Subject
%PLease note that this is a very lightweight program that I designed to be as small as possible in the actual code
var font1 := Font.New ("Consolas:16:italic")
var actmark, outof, percent, storetotal, average, total : real
var name1, subject1 : string
var test_number, y : int
%Obtaining the Titles
put "What is your name?"
get name1 : *
put "What Subject will you be calculating the average for?(or type t for school average)"
get subject1 : *
if subject1 = "t" then
    subject1 := "School Average"
end if
%Making sure that the running numbers are all set to zero, when I didnt do this, some variables gave me errors in the calculation and others would cause the program to not run
y := 410
test_number := 0
percent := 0
total := 0
cls
%This is the start of the actual values for the tests
%I had A LOT of trouble finding a way to store the numbers I got from the percent. It took me 3hrs of redoing the entire loop to finaly figure out how to do this(I redid the program on paper.
%I have done all the assignments you gave us on paper before the actual programming aspect started
%I may have done it slower due to me writing the possible inputs and outputs of the program on three seperate sheets
%If you want to see my rough notes ask me, I'm very proud of them
loop
    %I love naming the variables what they actually are so I named the storetotal as a temporary place to get the totals
    storetotal := total
    put "Please enter what mark you got or -9 to calculate the average for " + subject1
    get actmark
    exit when actmark = -9
    put "What was this out of?"
    get outof
    %Me getting the percent
    percent := (actmark / outof) * 100
    if percent > 100 then
        put "Are you asian??"
    end if
    %The total is the total running sum of the current operation so far
    total := storetotal + percent
    %The x value is a count of how many tests were taken into account by the program so that later we can actually use a correct number of tests to divide the running sum of the averages
    test_number := test_number + 1
    y := y - 65
    %This particular piece of code does not obey me, it cannot draw past 6 tests for some reason
    %I've tried multiple ways to fix this but none have worked
    Font.Draw ("Test " + intstr (test_number) + ":" + frealstr (percent, 0, 1) + "%", 300, y, font1, black)
end loop
%This makes it look pretty
cls
%The average of the subject is this
average := (total / test_number)
%Showing the average to the user
y := 250
Font.Draw ("Your average was " + frealstr (average, 0, 1) + "%", 150, y, font1, black)
%I wanted to write a loop but I wasn't able to stop the repeating messages
y := y - 20
if average > 80 then
    Font.Draw ("Congratulations," + name1, 150, y, font1, black)
    y := y - 20
    Font.Draw ("you are on your way to the honor roll", 150, y, font1, black)
    y := y - 20
    Font.Draw ("with " + frealstr (average, 0, 1) + "% in " + subject1, 150, y, font1, black)
end if
if average > 90 then
    y := y - 40
    Font.Draw ("You are also on your way", 150, y, font1, black)
    y := y - 20
    Font.Draw ("to the Principals List!!", 150, y, font1, black)
end if
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Oct 09, 2014 6:50 pm   Post subject: RE:Can anyone make suggestions to make this program better?

Your comments are actually pretty good, and your variable names too. You shouldn't have to love naming your variables after what they do, because that's how it should be done. It's actually very bad form to not do that.
Nathan4102




PostPosted: Thu Oct 09, 2014 6:52 pm   Post subject: RE:Can anyone make suggestions to make this program better?

I don't have a turing compiler on this computer so I can't test anything but glancing over the code, I see no issues. Unfortunately I can't help you with your drawing issue on this computer, if nobody helps you tonight than tomorrow I'll give it a shot.

One thing to note though, unless you're specifically challenged to keep code length to a minimum, ALWAYS treat efficiency and readability over code shortness. Code length is not necessarily a bad thing, longer code can be more efficient than short code, and is usually neater and easier to read and modify later. Not that your code looks like you really pressed for shortness, just based on the comment you made at the top.

It looks good though, keep it up and good luck!
Tony




PostPosted: Thu Oct 09, 2014 7:00 pm   Post subject: Re: Can anyone make suggestions to make this program better?

Instead of asking for marks and total separately, you could get one line of input in the form of "56/60" and parse that into appropriate components yourself.
PR069 @ Thu Oct 09, 2014 6:31 pm wrote:

if percent > 100 then
put "Are you asian??"
end if

Racial stereotypes are a base of many jokes, but might not be appropriate in a classroom setting. Messaging aside, this out-of-bounds types of checks _are_ a good thing to do.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
PR069




PostPosted: Fri Oct 10, 2014 7:23 am   Post subject: Re: Can anyone make suggestions to make this program better?

Im sorry about the racism Me and my friends were fooling around, I will ensure that all of this code has been checked over and thanks for the support that I should not just strive for shorter code.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: