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

Username:   Password: 
 RegisterRegister   
 Report Card Program (IF/ELSIF CONDITIONS and CASE STATEMENTS)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Loomis




PostPosted: Sat Oct 31, 2009 4:19 pm   Post subject: Report Card Program (IF/ELSIF CONDITIONS and CASE STATEMENTS)

What is it you are trying to achieve?
I'm trying to make a program that asks for a person's name, the names of four courses that she take and the mark she recieved for each course.
Then, the program should calculate the person's average to one decimal place and determine how many credits the person has earned and output an attractively designed report card.

What is the problem you are having?
The problem is that I can't seem to use the if/elsif conditions or a case statement to make the program output how many credits they've earned.

Describe what you have tried to solve this problem
This is what I have so far :

Turing:


if mark1 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark2 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark3 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark4 > 50 then
    creditsEarned := creditsEarned + 1
end if



Well, it's obvious that it doesn't work correctly and the style is really bad.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is the whole program:

Turing:


var name, course1, course2, course3, course4 : string
var mark1, mark2, mark3, mark4, sum : real
var creditsEarned : int

creditsEarned := 0
sum := 0

put "What is your full name?"
get name : *
put "What are four courses you take?"
get course1, course2, course3, course4
put "What are the marks you have recieved for those courses?"
get mark1, mark2, mark3, mark4
sum := sum + mark1 + mark2 + mark3 + mark4

if mark1 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark2 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark3 > 50 then
    creditsEarned := creditsEarned + 1
elsif mark4 > 50 then
    creditsEarned := creditsEarned + 1
end if

put "Credits Earned: ", creditsEarned
put ""
put "" : 3, "Academic School"
put ""
put "Name: ", name
put ""
put "Course:" : 15, "Mark:"
put ""
put course1 : 15, mark1
put ""
put course2 : 15, mark2
put ""
put course3 : 15, mark3
put ""
put course4 : 15, mark4
put ""

put "Average: ", sum / 4 : 0 : 1



How can I make the program correctly calculate the credits earned and how can I make the report card design more attractive and the codes more user friendly?

Please specify what version of Turing you are using
Version 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Superskull85




PostPosted: Sat Oct 31, 2009 5:29 pm   Post subject: Re: Report Card Program (IF/ELSIF CONDITIONS and CASE STATEMENTS)

The problem is that you have grouped your if statements together; you will never reach branch two unless branch one failed, etc. What you want to have are separate, non-grouped, if statements for each mark. For example the way you did it was:

Turing:
if Mark1 > PassingGrade then
    add one earned credit
elsif Mark2 > PassingGrade then
    add one earned credit
end if

If you wanted to check all marks you would need to have separate if statements:

Turing:
if Mark1 > PassingGrade then
    add one earned credit
end if

if Mark2 > PassingGrade then
    add one earned credit
end if
...

This way each mark is checked even if the first check comes true. Smile
Loomis




PostPosted: Sun Nov 01, 2009 7:43 pm   Post subject: Re: Report Card Program (IF/ELSIF CONDITIONS and CASE STATEMENTS)

Oh, I completely understand! Thanks a bunch. Very Happy
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  [ 3 Posts ]
Jump to:   


Style:  
Search: