Join 307,090 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,039 people online right now. Registration is fast and FREE... Join Now!
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:
CODE
#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; }
public static void Main() { Console.WriteLine("Please enter your name..."); string name = Console.ReadLine(); Console.WriteLine("Hello " + name + ", Welcome to Dream.In.Code"); }
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
#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";
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!
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
CODE
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 Feb, 2009 - 04:33 PM
</head> <body> <script type="text/javascript"> var name=(prompt("Enter name: ","")); /* <![CDATA[ */ document.write("<p><h3>Hello " + name + " . Welcome to Dream In Code, where all your wildest dreams come true!</h3></p>"); /* ]]> */ </script> </body> </html>
HAI CAN HAS STDIO? I HAS A YERNAME VISIBLE "Please enter your name..." GIMMEH LINE YERNAME VISIBLE "Hello "! VISIBLE YERNAME! VISIBLE ", Welcome to Dream.In.Code" KTHXBYE
class hello METHODS method init: local var name = input_String( "What is your name?\n" ) println( "Hello $. Welcome to Dream In Code" (name) ) endClass
This post has been edited by 5thWall: 3 Mar, 2009 - 12:14 AM