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

Username:   Password: 
 RegisterRegister   
 Student mark's program - need help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
worschtl




PostPosted: Thu Mar 22, 2007 1:16 pm   Post subject: Student mark's program - need help

Hello!

For Grade 11 Computerengineering I have to complete the attached assignment. I' ve been desperately trying to do so, but still couldn't figure it out myself. The reason why is probably that I didn't take Grade 10. Still, my teacher is not willing to help me Crying or Very sad ... hopefully you guys will, that would just be awsome!

This is what I' ve got so far:

code:

procedure clearScreen
    var ch : string (1)
    put "Press ENTER to clear the screen and continue."
    getch (ch)
    cls
end clearScreen

var marks : array 1 .. 6, 1 .. 50 of int    %stores the student's marks
var studentnumber : string                  %The studentnumber
var mark : string                           %
var nomark : string
var Test : boolean
var flag : string
var test : string
var num : int
var num1 : int
var num2 : int
var upper_bounds : string


flag := "continue"

loop
    put "Please enter a seven digit student number. Type in 9999999 to quit."
    get studentnumber                                                           %gets the studentnumber
    if studentnumber = "9999999" then                                           %leaves the loop when the studennumber is 9999999
        flag := "Exit"
        if flag = "Exit"
                then
            exit
        end if
    end if

    Test := strintok (studentnumber)                                            %checks the input
    if Test then
        num := strint (studentnumber)
    else
        put studentnumber, " is not a valid student number."
    end if
    if Test then
        if length (studentnumber) < 7 then
            put "The student number must be 7 digits long. Type 0's in the beginning if necessary"
        elsif length (studentnumber) > 7 then
            put "The student number must be 7 digits long. Type 0's in the beginning if necessary"
        elsif length (studentnumber) = 7 then
            exit when num > 0
            if num <= 0 then
                put studentnumber, " is not a valid student number."
            end if
        end if
    end if
end loop
loop
    if studentnumber = "9999999" then                                    %leaves the loop when the studennumber is 9999999
        flag := "Exit"
        flag := "Exit"
        if flag = "Exit"
                then
            exit
        end if
    end if
    put "Please enter the number of marks for student: ", studentnumber
    put "You cannot enter more than six test marks. "
    get upper_bounds                                                     %gets the number of marks
    if strintok (upper_bounds) = true then                               %checks the input
        num1 := strint (upper_bounds)
        if num1 >= 1 and num1 <= 6 then
            flag := "Exit"
            if flag = "Exit"
                    then
                exit
            end if
        end if
        if num1 < 1 or num1 > 6 then
            put "You must enter a number between 1 to 6."
        end if
    else
        put upper_bounds, " is not a valid integer."
    end if
end loop
loop
    for i: 1..num1
    if studentnumber = "9999999" then                                    %leaves the loop when the studennumber is 9999999
        flag := "Exit"
        if flag = "Exit"
                then
            exit
        end if
    end if
    put "Please enter the test ", i ," mark for student ", studentnumber, " as a number between 1 to 100."
    get mark                                                             %gets the student's mark
    if strintok (mark) = true then                                       %checks the input
        num2 := strint (mark)
        if num2 < 0 or num2 > 100 then
            put "Your value of ", mark, " was not between 0 to 100."
        end if
        if num2 >= 0 or num2 <= 100 then
            flag := "Exit"
            if flag = "Exit"
                    then
                exit
            end if
        else
            put "Your value of ", mark, " was not between 0 to 100."
        end if
    end if
    end for
end loop


Now I don't know how to move on to the next mark in the 3rd loop, when a valid mark was entered. In addition, I think I'm missing arrays and i dont really know how to use them, even though having worked through the tutorial on this site. Sad

Hope you guys can help me, the assignment is already overdue...
Thank you very much in advance, regards

worschtl Wink



Unit2_Assignment_4.doc
 Description:

Download
 Filename:  Unit2_Assignment_4.doc
 Filesize:  198 KB
 Downloaded:  124 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Mar 22, 2007 2:31 pm   Post subject: RE:Student mark\'s program - need help

The forum policy is to not directly answer homework questions, though we will help you learn concepts and ideas needed to solve your assignments.

Uploading your entire assignment is a bad idea, your best bet is to ask specific questions, such as about troubles you're having with arrays. (Best to specify what, otherwise you'll just get directed to the tutorials again)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
worschtl




PostPosted: Thu Mar 22, 2007 3:51 pm   Post subject: Re: Student mark's program - need help

Alright, so how would I use an array in the program above, to save the student numbers 1-50 and the marks 1-6t for each of them in an array?

Thanks, worschtl Wink
Clayton




PostPosted: Thu Mar 22, 2007 3:57 pm   Post subject: Re: Student mark's program - need help

The easiest way would be to use a custom type. Check out the records and types tutorial in the Turing Walkthrough for more info, but some sample code:

Turing:

var students : array 1 .. 50 of
    record
        marks : array 1 .. 6 of int
        name : string
    end record

put "Enter student 1's first mark"
get students (1).marks (1)
worschtl




PostPosted: Thu Mar 22, 2007 4:09 pm   Post subject: Re: Student mark's program - need help

Thanks for your answer,

I'll try to apply that to my program now. But I've got another problem: How can I get the 3rd loop to run just as many times as the user entered that there are marks to be entered?
Tony




PostPosted: Thu Mar 22, 2007 6:58 pm   Post subject: RE:Student mark\'s program - need help

You would want to have a for loop that would run up to its limit, and then stop.
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: