"Hello DIC" in every programing language

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

66 Replies - 8669 Views - Last Post: 25 November 2010 - 04:47 PM

#1 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

"Hello DIC" in every programing language

Posted 27 February 2009 - 05:48 PM

Here's the deal. Post a program that does these three things:
1. Asks user for his/her name
2. Stores the name in some variable.
3. Print "Hello, " [the user's name, replace with the name] " welcome to DIC" or Dream.In.Code or something to the effect.
ANY programing language and library combination is allowed (i.e. C++, C/Ncurses, Python, Qt). GUI allowed. If you're not sure users wold know, post short instructions on how to compile/run. I'll start with a C++ implementation using the C++ standard library:
#include<iostream>
#include<string>
using namespace std;

int main()
{
  string a;
  cout << "Type your name: ";
  getline(cin, a);
  cout << "Hello, " << a << ". Welcome to Dream.In.Code\n";
  return 0;
}


Please make sure the code works before posting.


Replies To: "Hello DIC" in every programing language

#2 Core   User is offline

  • D.I.C Lover
  • member icon

Reputation: 785
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 05:54 PM

Moved to Games/Puzzles/Trivia/Jokes. :)

#3 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 06:09 PM

Simply place in a C# console application

public static void Main()
{
	Console.WriteLine("Please enter your name...");
	string name = Console.ReadLine();
	Console.WriteLine("Hello " + name + ", Welcome to Dream.In.Code");
}



#4 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 06:38 PM

Good one PsychoCoder, I'll get this into Mono ('cause I don't use Window$).

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 07:04 PM

BASH/sh:
#!/usr/bin/env bash

echo -n "Enter your name: "
read name
echo "Hello $name, Welcome to Dream.In.Code"



Python:
#!/usr/bin/env python

name = raw_input("Enter your name: ")
print "Hello " + name + ", Welcome to Dream.In.Code"



#6 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 07:05 PM

Console App in VB.Net

Module Module1
 Sub Main()
  Console.WriteLine("Please enter your name...")
  Console.WriteLine("Hello {0} Welcome to Dream.In.Code", Console.ReadLine)
 End Sub
End Module



#7 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 07:40 PM

Okay, you made me do this...
Common Lisp:
(defun mk-prompt (string)
  (format *query-io* string)
  (read-line *query-io*)
)
(defvar name (mk-prompt "What's your name: "))
(format t "Hello ~a, welcome to DIC" name)

EAT THAT!

Don't forget you CAN make a GUI or use some library! MORE less well known languages PLEASE!

#8 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: "Hello DIC" in every programing language

Posted 27 February 2009 - 10:28 PM

Here's a welcome in Haskell

main = do
   putStrLn "Please enter your name..."
   name <- getLine
   putStrLn ("Hello " ++ name ++ ", Welcome to Dream.In.Code")



#9 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 08:21 AM

Ruby with Qt 4:
bin/env ruby
require 'Qt4'

include Qt
class Dic < Qt::Widget
  slots 'mesg()'
  def initialize(parent = nil)
	super()
	label = Qt::Label.new(tr('Hi. What\'s your name'), self)
	@text = Qt::LineEdit.new(tr(''), self)
	connect(@text, SIGNAL('returnPressed()'), self, SLOT('mesg()'))
	layout = Qt::VBoxLayout.new()
	layout.addWidget(label)
	layout.addWidget(@text)   
	setLayout(layout)
  end
  def mesg()
	name = @text.text()
	ret = MessageBox::warning(self, "Hi",
	tr("Hi, "+name+". Welcome to Dream.In.Code!"),
	MessageBox::Ok | MessageBox::Cancel,
	MessageBox::Ok)
	$qApp::quit()
  end
end

app = Qt::Application.new(ARGV)

widget = Dic.new()
widget.setWindowTitle(Qt::Widget::tr("Hello DIC"))
widget.show()

app.exec()

First GUI app posted.

#10 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 08:58 AM

Perl
#Hello World in Perl
#Get the users name
#input
print "Please enter your name...";
$name = <STDIN>;
#output
print "Hello "
print $name;
print ", Welcome to Dream.In.Code\n";



#11 ayman_mastermind   User is offline

  • human.setType("geek");
  • member icon

Reputation: 127
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 11:33 AM

In Java! :)
import java.util.Scanner;
public class Welcome {
	public static void main(String[] args){
		Scanner Input = new Scanner(System.in);
		System.out.println("Please enter your name: ");
		String name = Input.next();
		System.out.println("Hello " + name + " Welcome to Dream.In.Code!");
	}
}


btw, happy birthday to Dream.In.Code and greetings to all members of this helpful and warm community! ;)

#12 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 11:53 AM

BASIC
10 name As String
20 Input "Please enter your name...", name
30 Print
40 Print "Hello "; name; ", Welcome to Dream.In.Code"
50 Sleep 
60 End



#13 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 12:18 PM

When I finish the RPN calculator I'm working on, I'm taking a crack as gas assembler. C'mon, beat me to it!!

#14 krzysz00   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 83
  • Joined: 25-February 09

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 04:19 PM

View Postayman_mastermind, on 28 Feb, 2009 - 11:33 AM, said:

In Java! :)
import java.util.Scanner;
public class Welcome {
	public static void main(String[] args){
		Scanner Input = new Scanner(System.in);
		System.out.println("Please enter your name: ");
		String name = Input.next();
		System.out.println("Hello " + name + " Welcome to Dream.In.Code!");
	}
}


btw, happy birthday to Dream.In.Code and greetings to all members of this helpful and warm community! ;)

My Java one is shorter than yours
import java.io.Console;
public class dic
{
	public static void main(String args[])
	{
	Console dream = new System.console();
	String line = dream.readLine("Type your name: ");
	echo.printf("You typed %s.%n", line);
	}
}

This post has been edited by krzysz00: 28 February 2009 - 05:33 PM


#15 ericr2427   User is offline

  • D.I.C Regular
  • member icon

Reputation: 40
  • View blog
  • Posts: 378
  • Joined: 01-December 08

Re: "Hello DIC" in every programing language

Posted 28 February 2009 - 07:59 PM

PHP! Pretty much the worst language to do this in...
<?php
if (isset($POST['submit'])) {
  echo "Hello, ".$_POST['name'].", welcome to DIC!";
}
else {
  echo '<form action="'.$_SERVER[php_self].'" method="post">
		   <h3>Type your name: </h3>
		   <input type="text" name="name" size="25">
		   <input type="submit" name="submit">
		   </form>';
}
?>



  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »