Turn on thread page Beta

Higher computing 2014/15 coursework penny's decking watch

Announcements
    Offline

    0
    ReputationRep:
    Can someone help me? My class has just been verified and i haven't even started on the program for Penny's Decking and it's to be done in the next couple of weeks... We're doing it in Python, but i have no idea what to do because i'm terrible at programming and the teacher won't help me.
    Offline

    19
    ReputationRep:
    (Original post by CharliesLapras)
    Can someone help me? My class has just been verified and i haven't even started on the program for Penny's Decking and it's to be done in the next couple of weeks... We're doing it in Python, but i have no idea what to do because i'm terrible at programming and the teacher won't help me.
    Unfortunately I do not know python. If your teacher refuses to help you, then get him/her fired for not doing her job.
    Offline

    0
    ReputationRep:
    hey guys, i really need help. i am the only person doing this coursework from standard grade so i haven't got enough support. i have read what you all wrote but do not understand it. i am doing it on visual basics if there is anyone who could help me understand the programming that would be much appreciated. thank you.
    Offline

    19
    ReputationRep:
    (Original post by toffie)
    hey guys, i really need help. i am the only person doing this coursework from standard grade so i haven't got enough support. i have read what you all wrote but do not understand it. i am doing it on visual basics if there is anyone who could help me understand the programming that would be much appreciated. thank you.
    How much of VB do you know?
    Offline

    0
    ReputationRep:
    (Original post by Async)
    How much of VB do you know?
    the basics, like how to make a simple programme. i was going to use a drop box menu on the forum but i don't know the code for it.
    Offline

    19
    ReputationRep:
    (Original post by toffie)
    the basics, like how to make a simple programme. i was going to use a drop box menu on the forum but i don't know the code for it.
    I would help you but I'm very busy atm.
    Offline

    0
    ReputationRep:
    guys I have a question ..how would u deal with unexpected input? already set up the variable as Integer (it needs to be an integer) but the input is e.g. a letter or question mark? how would you code it so the program doesn't crash every time the user types in something else than simple 1,2,3etc.? (using VB)
    Offline

    19
    ReputationRep:
    (Original post by Maggie9089)
    guys I have a question ..how would u deal with unexpected input? already set up the variable as Integer (it needs to be an integer) but the input is e.g. a letter or question mark? how would you code it so the program doesn't crash every time the user types in something else than simple 1,2,3etc.? (using VB)
    There are multiple ways to deal with unexpected input depending on the specific case. You can use validation or exception handling.

    For example, if you are expecting an Integer you can use Integer.TryParse() method to try and "parse" the input. IntegerTryParse() will return true if the input can be converted to an Integer and false if it can't.

    However, you can also use a TryCatch statement to catch errors. It is the most common way for handling errors, but it should be used as a last resort if there is no way you can prevent the error in the first place. A try catch statement works by trying a bit of code, and if any errors occur, it will catch and execute a set of codes.

    You could use a TryCatch statement in your case, but it is usually better to prevent an error than to catch one. For example, if I were a police man, you would regard me as a better police man if I prevented a criminal from killing someone, than if I waited for the criminal to kill someone then arrested them. It's the same philosophy. A TryCatch statement waits for the error before catching it. So in your case it would be better to validate the input by using Integer.TryParse()

    This is the VB.NET example of the Integer.TryParse() example

    Spoiler:
    Show

    Code:
    Console.Title = "Input validation example"
    
    
            Console.Write("Please enter a number: ")
            Dim userInput As String = Console.ReadLine()
    
    
            Dim input As Integer
    
    
            If Integer.TryParse(userInput, input) Then
                Console.WriteLine("Great, that is valid input")
            Else
                Console.WriteLine("Sorry that is not an integer")
            End If
    
    
            Console.ReadLine()




    This is the TryCatch solution

    Spoiler:
    Show

    Code:
    Console.Title = "Input validation example"
    
    
            Try
                Console.Write("Please enter a number: ")
                Dim input As Integer = Integer.Parse(Console.ReadLine())
    
    
                Console.WriteLine("Great, that is valid input")
    
    
            Catch ex As Exception
                Console.WriteLine("Invalid Input: " & ex.Message)
            End Try
    
    
            Console.ReadLine()





    The both work the same way, but if possible, ALWAYS prevent the error from happening in the first place by using validation checks. If there is not viable way of preventing the error, then it would be appropriate to use a try catch statement.

    Hope that helps.
    Offline

    0
    ReputationRep:
    (Original post by Async)
    There are multiple ways to deal with unexpected input depending on the specific case. You can use validation or exception handling.

    For example, if you are expecting an Integer you can use Integer.TryParse() method to try and "parse" the input. IntegerTryParse() will return true if the input can be converted to an Integer and false if it can't.

    However, you can also use a TryCatch statement to catch errors. It is the most common way for handling errors, but it should be used as a last resort if there is no way you can prevent the error in the first place. A try catch statement works by trying a bit of code, and if any errors occur, it will catch and execute a set of codes.

    You could use a TryCatch statement in your case, but it is usually better to prevent an error than to catch one. For example, if I were a police man, you would regard me as a better police man if I prevented a criminal from killing someone, than if I waited for the criminal to kill someone then arrested them. It's the same philosophy. A TryCatch statement waits for the error before catching it. So in your case it would be better to validate the input by using Integer.TryParse()

    This is the VB.NET example of the Integer.TryParse() example

    Spoiler:
    Show

    Code:
    Console.Title = "Input validation example"
    
    
            Console.Write("Please enter a number: ")
            Dim userInput As String = Console.ReadLine()
    
    
            Dim input As Integer
    
    
            If Integer.TryParse(userInput, input) Then
                Console.WriteLine("Great, that is valid input")
            Else
                Console.WriteLine("Sorry that is not an integer")
            End If
    
    
            Console.ReadLine()




    This is the TryCatch solution

    Spoiler:
    Show

    Code:
    Console.Title = "Input validation example"
    
    
            Try
                Console.Write("Please enter a number: ")
                Dim input As Integer = Integer.Parse(Console.ReadLine())
    
    
                Console.WriteLine("Great, that is valid input")
    
    
            Catch ex As Exception
                Console.WriteLine("Invalid Input: " & ex.Message)
            End Try
    
    
            Console.ReadLine()





    The both work the same way, but if possible, ALWAYS prevent the error from happening in the first place by using validation checks. If there is not viable way of preventing the error, then it would be appropriate to use a try catch statement.

    Hope that helps.

    Thanks a lot for your help
    Offline

    0
    ReputationRep:
    Would anyone be able to give a quick bit of code for opening & reading in a file, writing to it & closing it? Please
 
 
 
Poll
Are you chained to your phone?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.