Page 1 of 1 1
Topic Options
#199773 - 2010-09-05 08:25 PM Very very basic question
Asakura Offline
Just in Town

Registered: 2010-09-05
Posts: 3
Loc: Netherlands
Hi there everyone, recently I have started my internship at an IT department at a company.

Now I have a little assignment where I have to make some assignments in KiXtart. But even on the first "sheet" I have run into some problems I just can't figure out.

I have to create a function that can multiply/divide/add/subtract integers and then load them in the variable.

But I just can't add the right parameter to make a distinction between what to do.

My guess is that I have to declare the different parameters so it knows what to do. But I just can't figure it out.

 Code:
$var2 = som2(1,8,"+")
? "var= " + $var2


Function som2($num1, $num2,"+","-","*","/")
	Dim $num3
	Dim $num2
	Dim $num1
	"+" = +
	
	Select Case
	
		Case $som2 = $num1 "+" $num2
			$num1 + $num2
	EndSelect
		
EndFunction



Could someone guide me in the right direction, but not spoil the whole assignment?

Thanks!


Edited by Asakura (2010-09-05 08:26 PM)

Top
#199774 - 2010-09-05 09:06 PM Re: Very very basic question [Re: Asakura]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You need to specify the operator when calling the function. The function itself should check what operator (-, +, / or *) is needed and act accordingly. The outcome can be stuffed into a variable with the same name as the function so you get some data from the function.

Best practice would be to dim all used variables inside the function except the ones used as parameters for the function. A check if all parameters are like they should be (integer and the used operators) would also be great to avoid unexpected results like add 1 to 8 resulting in 81 instead of 9.


If you are totally stuck and there is absolutely no way out check out the spoiler I added. Working example and not best practice coding but it will get you somewhere. Try to write it yourself first ;\)

Warning, Spoiler:

 Code:
Break on

$var2 = Math(1,8,"add")
? "var = " + $var2


Function Math($num1, $num2, $operator)
	
Select
	Case $operator = "add"
		$math = $num1 + $num2
	Case $operator = "divide"
		$math = $num1 / $num2
	Case $operator = "multiply"
		$math = $num1 * $num2
	Case $operator = "subtract"
		$math = $num1 - $num2
EndSelect
		
EndFunction

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#199775 - 2010-09-05 09:43 PM Re: Very very basic question [Re: Mart]
Asakura Offline
Just in Town

Registered: 2010-09-05
Posts: 3
Loc: Netherlands
Many many thanks! This has helped me a lot!

I have quite some assignments left so I will undoubtedly return here.

Top
#199776 - 2010-09-05 10:26 PM Re: Very very basic question [Re: Asakura]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Did you open the spoiler
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#199777 - 2010-09-05 10:30 PM Re: Very very basic question [Re: Mart]
Asakura Offline
Just in Town

Registered: 2010-09-05
Posts: 3
Loc: Netherlands
I took a quick peek because I kept trying wrong parameters, but as soon I saw how I was supposed to create it, I was able to finish it myself \:\)

Edited by Asakura (2010-09-05 10:31 PM)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 320 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.134 seconds in which 0.107 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org