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

Username:   Password: 
 RegisterRegister   
 Getting the "Invalid integer input" error and I don't know why
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cactussenpai




PostPosted: Fri Mar 25, 2016 7:05 pm   Post subject: Getting the "Invalid integer input" error and I don't know why

What is it you are trying to achieve?
I am writing a program which tells a student their average if they input four marks.


What is the problem you are having?
When the program gets to where the user inputs the marks, it crashes, giving the error.


Describe what you have tried to solve this problem
I have tried changing many places of the program but to no avail.

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


Turing:


setscreen ("graphics:800;500")

var font1 : int := Font.New ("candara:12:bold")
var font2 : int := Font.New ("candara:12")
var font3 : int := Font.New ("times:12:italic")
var name : string
var mark1 : int
var mark2 : int
var mark3 : int
var mark4 : int
var text1 : string := "It's that time again, students. It's time for grades!! If you'd like to know your average, please follow the steps below."

put "\n"
put "\n"
put "\n"
procedure textDelayFont (text : string, x, y, font, clr, timeDelay : int)
    var xPos := x
    for i : 1 .. length (text)
        Font.Draw (text (i), xPos, y, font, clr)
        xPos += Font.Width (text (i), font)
        delay (timeDelay)
    end for
end textDelayFont
textDelayFont (text1, 0, 450, font2, red, 50)
Font.Draw ("Please type your full name: ", 0, 425, font1, black)
get name
put "\n"
put "\n"
put "\n"
Font.Draw ("Please put your marks in percent(4 marks): ", 0, 370, font1, black)
get mark1
get mark2
get mark3
get mark4

put "\n"
var average : int := (mark1 + mark2 + mark3 + mark4) div 4

Font.Draw ("Your average is: ", 0, 290, font1, blue)

Font.Draw (intstr (average), 150, 290, font1, red)




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




PostPosted: Fri Mar 25, 2016 8:43 pm   Post subject: Re: Getting the "Invalid integer input" error and I don't know why

get will stop reading input at the first whitespace character. So If I enter my name as
code:
first last
then it will only read "first" and leave the rest. The next time you call get it will resume where it left off and read "last". Since "last" isn't an integer you get an error.
Gaming Lyfe




PostPosted: Tue Mar 29, 2016 6:24 pm   Post subject: RE:Getting the "Invalid integer input" error and I don\'t know why

You could use the command get:*, which allows the get command to take in multiple words instead of just one.

ex.

get:* name
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: