From: Michael Ulm Date: 2007-04-25T22:31:24+09:00 Subject: Re: C++ code into Ruby, I need it fast, no time for RTFM Andrei Ursan wrote: > [code] > #include > #include > > void r_string(int n, int v[]) > { > int i; > > for(i=0;i { > cout<<"v["< cin>>v[i]; > } > > } > > void p_string(int n, int v[]) > { > int i; > cout<<"\nThe string is : "; > > for(i=0;i cout< > } > > float avarage_string(int n, int v[]) > { > int i,s=0; > float av; > for(i=0;i s+=v[i]; > > av=(float)s/n; > > return av; > } > > void main() > { > clrscr(); > > int no, a[20]; > cout<<" no = "; > cin>>no; > r_string(no,a); > p_string(no,a); > > cout<<"String avarage is : "< > getch(); > } > [/code] > > Strings value are read from the keyboard, and i need a getch and clrscr > method. > And how can I export the ruby code into *.exe ? > > Can somebody translate this into ruby ? I need it fast... > Well, since you ask _that_ nicely... This may get you started print "number of entries: " no = gets.to_i a = [] no.times do |i| print "enter item nr. #{i}: " a << gets.to_i end p a puts a.inject(0){|s, x| s + x}.to_f / a.size unless a.empty? It's rather quick-and-dirty, but then, so was your C++ code. HTH, Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-542, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com --------------------------------------------------------------- This e-mail is only intended for the recipient and not legally binding. Unauthorised use, publication, reproduction or disclosure of the content of this e-mail is not permitted. This email has been checked for known viruses, but ISIS accepts no responsibility for malicious or inappropriate content. ---------------------------------------------------------------