Hello,
how do i write this C++ source code in ruby:
cout<<"Enter field length: ";
Field;
for(i=0;i<Max;i++)
{
cout<<“Insert “<<i<<”. Number:”;
Field[i];
}
I hope it´s correct. The programme should do the following:
- How many numbers do you wanna have?
- Please enter number 1… 2… 3… etc. till the end.
···
–
freenet Grusskarten:
Schicken Sie Ihren Freunden einen Gruss.
Jetzt mit Sound: http://www.freenet.de/tipp/gruss
stefanocheri@freenet.de wrote:
Hello,
how do i write this C++ source code in ruby:
By putting some effort in to learning how to use Ruby.
Grab a copy of Programming Ruby from http://www.rubycentral.com
Rob
Hi –
Hello,
how do i write this C++ source code in ruby:
cout<<"Enter field length: ";
Field;
for(i=0;i<Max;i++)
{
cout<<“Insert “<<i<<”. Number:”;
Field[i];
}
I hope it´s correct. The programme should do the following:
- How many numbers do you wanna have?
- Please enter number 1… 2… 3… etc. till the end.
Something like:
print "Enter field length: "
len = gets.chomp.to_i
fields =
len.times do |i|
print "Please enter number #{i+i}: "
fields << gets.to_i
end
or if you want that nice functional programming feel:
fields = (0…len).map do |i|
print "Please enter number #{i}: "
gets.to_i
end
David
···
On Wed, 11 Dec 2002 stefanocheri@freenet.de wrote:
–
David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav
stefanocheri@freenet.de wrote:
Hello,
how do i write this C++ source code in ruby:
cout<<"Enter field length: ";
Field;
puts “Enter field length”
max = gets # vars starting with capital letters are constants
# plus, you want to input Max, not Field in your C++ code
# anyway
for(i=0;i<Max;i++)
{
cout<<“Insert “<<i<<”. Number:”;
Field[i];
}
field = # or field = Array.new
0.upto(max) {|i|
print "Insert #{i}. Number: " # puts adds a newline; print does not
field[i] = gets # arrays can be grown dynamically
}
martin