## How to call a procedure with two or more given parameters

## How to call a procedure with two or more given parameters

(OP)

Hi, i am attempting to write a simple script to sum two given numbers:

#A simple script that sum two given numbers

proc Sum {number1 number2} {

return [expr $number1+$number2];

}

proc main {} {

puts "Sum between two numbers";

puts "";

puts -nonewline "Insert the numbers:"

flush stdout;

?

#sum given numbers

puts "The sum is: [Sum $number1 $number2]";

}

#call main

main;

What might i write in the place of question mark?

And, if i insert a string or a char in the place of numbers, what happens?

Thanks!

#A simple script that sum two given numbers

proc Sum {number1 number2} {

return [expr $number1+$number2];

}

proc main {} {

puts "Sum between two numbers";

puts "";

puts -nonewline "Insert the numbers:"

flush stdout;

?

#sum given numbers

puts "The sum is: [Sum $number1 $number2]";

}

#call main

main;

What might i write in the place of question mark?

And, if i insert a string or a char in the place of numbers, what happens?

Thanks!

## RE: How to call a procedure with two or more given parameters

## CODE

proc Sum {number1 number2} {

return [expr $number1+$number2]

}

proc main {} {

puts "Sum between two numbers"

puts ""

puts "Insert the numbers:"

puts -nonewline "number1 = "

flush stdout

gets stdin num01

puts -nonewline "number2 = "

flush stdout

gets stdin num02

#sum given numbers

puts "The sum is: [Sum $num01 $num02]"

}

#call main

main

## CODE

Sum between two numbers

Insert the numbers:

number1 = 1

number2 = 5

The sum is: 6

## RE: How to call a procedure with two or more given parameters

## RE: How to call a procedure with two or more given parameters

## CODE

#A simple script that sum two given numbers#

############################################

proc Sum {number1 number2} {

return [expr $number1+$number2]

}

proc main {} {

set number1 " ";

set number2 " ";

puts "Sum between two numbers"

puts ""

while {![string is integer -strict $number1] || ![string is integer -strict $number2]} {

puts "Insert the numbers:"

puts -nonewline "number1 = "

flush stdout

gets stdin number1

puts -nonewline "number2 = "

flush stdout

gets stdin number2

#check for invalid input (example a char or a string)

if {![string is integer -strict $number1] || ![string is integer -strict $number2]} {

puts "Error, repeat again";

}

}

#sum given numbers

puts "The sum is: [Sum $number1 $number2]"

}

#call main

main