Input/Print

Just starting out? Need help? Post your questions and find answers here.
rolstra
User
User
Posts: 11
Joined: Mon Mar 24, 2008 10:44 pm
Location: Austria

Input/Print

Post by rolstra »

Hi everybody,
I am an absolute beginner - so far. What I did not find out in studying the manual: How can I INPUT numeric data and how can I PRINT numeric data. The INPUT/PRINT statements so far seem to be only for string data. E.g. I want to:

INPUT number1
INPUT number2
x = number1 + number2
PRINT x

How does this work with purebasic?
Thank you,
Roland
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Code: Select all

number1 = Val(InputRequester("First Number", "Please make your input:", "")) ;INPUT number1
number2 = Val(InputRequester("Second Number", "Please make your input:", "")) ;INPUT number2
x = number1 + number2
MessageRequester("Sum",Str(x)) ;PRINT x
Here is one method to accomplish what you require using Requesters, one for input one for output. They deal only with strings, so numbers have to be converted both ways.

Another method involves console output (a text only screen). This method is the one you referred to with Input and Print. Use a method similar to the one I demonstrated to do the conversions betwen numbers and text.

Another method involves a GUI (graphic user interface) using gadgets for input and displaying the results.

I hope this helps.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Disclaimer, typed into the browser without checking for spelling or stupid mistakes

Code: Select all


OpenConsole()

    Num1.s = Input()
    Num2.s = Input()
    x.l = Val(Num1) + Val(Num2)

    PrintN(Str(x))
    Input()   ; give you a chance to see the output before the console screen vanishes


CloseConsole()

Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
rolstra
User
User
Posts: 11
Joined: Mon Mar 24, 2008 10:44 pm
Location: Austria

Post by rolstra »

Thank you very much,
that was exactly what I wanted to know.
Roland.
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

Rolstra,
If you are a complete beginner as you say, I would recommend for you to have a look at a site which has been put up by 1 of the forum users here ( blueznl ) which I think will probably help you a lot.
http://www.xs4all.nl/~bluez/datatalk/purebasic.htm
Post Reply