Manipulating input

BlitzMax Forums/BlitzMax Beginners Area/Manipulating input

Zacho(Posted 2009) [#1]
I have a program that is supposed to manipulate user input ( numbers) and then calculates values. Problem is I get an error "unable to create string to int". Any advice?


plash(Posted 2009) [#2]
It would be helpful to have the line of code which throws the error. Most likely the issue is your attempting to add strings with an integer variable.


Zacho(Posted 2009) [#3]
The only thing is I don't know how input can be manipulated (like numbers are for calculating)
AppTitle="Architecture->Digging a hold  by Me"

Type TheOnlyType
	Field width':Int
	Field length':Int
	Field depth':Int
EndType


Repeat 
Print "Created by Me. Cannot reproduce/sell/distribute in any form without consent"
Delay 1200
Print "This super easy program calculates everything about digging a hold"
Delay 1000
Print "Just type in the values. It's that easy!"

width=Input("What is the width of the hole? ")
Delay 700
length=Input("What is the height of the hole? ")
Delay 700
depth=Input("What is the depth of the hole? ")
Delay 700
Print "Calculating...hold on a sec...."
Delay 1000

Print "Cubic feet of dirt to dig: " + (width%+4)(length%+4)(depth%) + " ft"
Delay 500
Print "Cubic yards of dirt to dig: " + (width+4%*length%+4*depth%)/2 + " yds"
Delay 500
Print "Cost to dig the hole: $" + ((width%)(length%)(depth$)) * 6
Delay 500
Print "Amount of backfill: " + ((width% + width% + length% + length%) * depth%)/27 *2 + " cubic yards"
Delay 500
Print "How much dirt you have to hall away: " + ((width%+4)(length%+4)(depth%)) - (((width% + width% + length% + length%) * depth%)/27 *2)
Delay 500
Print "How much $$$ halling the dirt away costs: $" + (((width%+4)(length%+4)(depth%)) - (((width% + width% + length% + length%) * depth%)/27 *2))*50
Delay 500
Print "Total cost is: $" + ((((width%+4)(length%+4)(depth%)) - (((width% + width% + length% + length%) * depth%)/27 *2))*50) + (((width%)(length%)(depth$)) * 6)


Until KeyHit(27)



Brucey(Posted 2009) [#4]
One or two issues here :-)

May I suggest you start your BlitzMax adventure by using either Strict or SuperStrict at the top of your .bmx file ... a bit like this :
Strict

' .. the rest of your program

These two modes help the compiler to better understand what you are trying to do, and will give you more useful error messages.

Next.
Your "width" value, you have declared inside a Type. But, you try to use it as a normal variable.
Either, you don't want to use a Type, or you need to change how you use "width".

If you want to use TheOnlyType, then you'll need to create a new object :
Local dimensions:TheOnlyType = New TheOnlyType

after which you would refer to its fields with :
dimensions.width = .....


If you don't want to use the type, you can define "width" like :
Local width:int


To get a value from Input(), you will need to convert the result it to a number. You have two ways to do this, but the easiest is to do this:
width = Int(Input("blah...."))

which converts the String to an Int. This way is called casting.


Zacho(Posted 2009) [#5]
Oh ok, thanks. This will prolly' fix my problem!


Zacho(Posted 2009) [#6]
Maybe not.....
Error
Expression of type 'Int' cannot be invoked


Strict
AppTitle="Architecture->Digging a hold  by ZaChO"

Global width:Int
Global length:Int
Global depth:Int

Repeat 
Print "Created by ZaChO. Cannot reproduce/sell/distribute in any form without consent"
Delay 1200
Print "This super easy program calculates everything about digging a hold"
Delay 1000
Print "Just type in the values. It's that easy!"

width = Int(Input("What is the width of the hole? "))
Delay 700
length=Int(Input("What is the height of the hole? "))
Delay 700
depth=Int(Input("What is the depth of the hole? "))
Delay 700
Print "Calculating...hold on a sec...."
Delay 1000

Print "Cubic feet of dirt to dig: " + (width+4)(length+4)(depth) + " ft"
Delay 500
Print "Cubic yards of dirt to dig: " + (width+4*length+4*depth)/2 + " yds"
Delay 500
Print "Cost to dig the hole: $" + ((width)(length)(depth)) * 6
Delay 500
Print "Amount of backfill: " + ((width + width + length + length) * depth)/27 *2 + " cubic yards"
Delay 500
Print "How much dirt you have to hall away: " + ((width+4)(length+4)(depth)) - (((width + width + length + length) * depth)/27 *2)
Delay 500
Print "How much $$$ halling the dirt away costs: $" + (((width+4)(length+4)(depth)) - (((width + width + length + length) * depth)/27 *2))*50
Delay 500
Print "Total cost is: $" + ((((width+4)(length+4)(depth)) - (((width + width + length + length) * depth)/27 *2))*50) + (((width)(length)(depth)) * 6)


Until KeyHit(27)


I really thought Blitmax could manipulate input that had a numeracle value, guess not...


Jesse(Posted 2009) [#7]
the compiler doesn't know what you are trying to do here:
(width+4)(length+4)(depth)

or here:
((width)(length)(depth))

the only way the compiler know it's a multiplication is with an asterisk "*". It doesn't know what to do with two sets of parenthesis unless you specify.


Zacho(Posted 2009) [#8]
Oh, but does the compiler recognize width+4?


Jesse(Posted 2009) [#9]
yes, but do you know the order of operations?
this:
(width+4)(length+4)(depth)

is not the same as this:
(width+4*length+4*depth)

anyway I thought area was: width * length * depth
why are you adding 4?


Zacho(Posted 2009) [#10]
you need two extra feet on each side to work on the exterior wall. when you are building a house


B(Posted 2009) [#11]
this:
Print "Cubic feet of dirt to dig: " + (width+4)(length+4)(depth) + " ft"


needs to be this:
Print "Cubic feet of dirt to dig: " + (width+4 * length+4 * depth) + " ft"


as well as in all the other print commands


xlsior(Posted 2009) [#12]
"digging a hold" -> "digging a hole", I presume?


Zacho(Posted 2009) [#13]
@B-Ya, I just caught that before I read your post. My program works fine except for a few math bugs.

@xlsior-didnt even see that before you mentioned it. lol