"Hello, welcome to CF" in every language

Motoxrdude

Active Member
Write the most concise, but clearly readable program according to this specification:

1. Say: "Hi! What's your name? "
2. User enters name.
3. Say: "Hello, (username)! Welcome to ComputerForum!"

You can also use a simple GUI, like a dialog box, to ask the question, input name, etc

Try not to hog too many languages. Give other posters a fair go at posting their example too. If you are posting an alternative version of code for a language that has already been posted, mention that it is an alternative version.

C
Code:
#include <stdio.h>

int main()
{
        char name[64];
        printf("Hi! What's your name? ");
        scanf("%s", &name);
        printf("Hello, %s! Welcome to ComputerForum!\n", &name);

        return 0;
}
 

brian

VIP Member
C++

Code:
#include <stdio.h>

int main()
{
        char name[64];
        printf("Hi! What's your name? ");
        scanf("%s", &name);
        printf("Hello, %s! Welcome to ComputerForum!\n", &name);

        return 0;
}
do i win :D joke :D:cool:
 

shenry

Member
Simple but effective

Batch
Code:
@echo off
echo Hi what's your name?
set /p name=
echo Hello %name%! Welcome to Computer Forum!
pause
 

munkyeetr

New Member
Perl
Code:
#!/usr/bin/perl

print "Hi! What's your name? ";
my $name = <STDIN>;
print "Hello $name! Welcome to ComputerForum!\n";
 
Last edited:

Vizy

New Member
man i really wanted to learn programming and stuff. They had a beginner programming book at borders and i was reading it and it sounds...interesting.
 

PabloTeK

Active Member
Pascal/Delphi

Code:
WRITELN('Hi! What's your name?');
READLN(name);
WRITELN('Hello ',name,' Welcome to ComputerForum!');
 

Motoxrdude

Active Member
NASM Assembly (i386)
Code:
; nasm hellocf.asm -f elf && ld hellocf.o -o hellocf

section .bss
    name resb 512

segment .text 
    ; Constant data:
    intro      db   "Hi! What's you're name? "
    sz_intro   equ  $-intro
    outro1     db   "Hello "
    sz_outro1  equ  $-outro1
    outro2     db   "! Welcome to Computer Forum!", 10
    sz_outro2  equ  $-outro2
    global _start

; Console in system call
console_in:
    mov eax, 3
    mov ebx, 0
    int 0x80
ret

; Console out system call
console_out:
    mov eax, 4
    mov ebx, 1
    int 0x80
ret

; Find first newline in input
get_len:
    mov edx, 0
    get_len_loop:
        inc edx
        cmp byte [name+edx], 10
    jne get_len_loop
ret

; Start, equivalent to C's "main"
_start:
    mov ecx, intro
    mov edx, sz_intro
    call console_out

    mov ecx, name
    mov edx, 512
    call console_in

    mov ecx, outro1
    mov edx, sz_outro1
    call console_out

    mov ecx, name
    call get_len
    call console_out

    mov ecx, outro2
    mov edx, sz_outro2
    call console_out

    ; System exit call
    mov eax, 1
    int 0x80
 

Cromewell

Administrator
Staff member
NASM Assembly (i386)
.....edited out for size
:D Someone else who knows x86 ASM! I hate interrupt programming :p

Code:
import java.io.*; 

public class ReadName { 

   public static void main (String[] args) { 

      System.out.println("Hi! What's your name?"); 

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 

      String userName = null; 
      Int good = 0;

      while (! good)
        try { 
           userName = br.readLine();
        } catch (IOException ioe) { 
           System.out.println("Error reading name, please try again.");
           System.out.println("Hi! What's you're name?");
           continue;
        } 
        finally {
           good = 1;
        }
      }
      System.out.println("Hi " + userName + "! Welcome to Computer Forum!"); 

   } 

}


C'mon, I am sure there is someone who knows a programming language not listed here!
I know a couple but I'm only doing 1 :p
 
Last edited:

Cromewell

Administrator
Staff member
C++

Code:
#include <stdio.h>

int main()
{
        char name[64];
        printf("Hi! What's your name? ");
        scanf("%s", &name);
        printf("Hello, %s! Welcome to ComputerForum!\n", &name);

        return 0;
}
do i win :D joke :D:cool:
I was thinking about writing the java version before. If you are going to call it C++ at least C++ize it :p

Since this is a correctional post, I'm not counting it as doing more than 1 language
Code:
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string name;

  cout << "Hi! What's your name?" << endl;
  cin >> name;
  cout << "Hi " << name << "! Welcome to Computer Forum!" << endl;

  return 0;
}
 

Punk

Moderator
Staff member
Javascript...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>whatever</title>
<script type="text/javascript">
var name=prompt("Hi what's your name?","")
alert("Hello "+name+",welcome to ComputerForum!")
</script>
</head>
<body>
</body>
</html>

That will dispaly step 3 in an alert box... You can use the document.write too but I'm lazy lol
 

kobaj

VIP Member
Basic Stamp

Code:
 serStr  VAR     Word
 waitin  VAR     Byte

Main:
DO
    DEBUG CLS, "Hi, how many characters in your name?",    CR
    DEBUGIN DEC waitin
    DEBUG "What's your name?"
    DEBUGIN STR serStr\waitin
    DEBUG CR, "Hello, ", STR serStr, "! Welcome to ComputerForum."
   PAUSE 5000
  LOOP
END

I spent waaaaay to damn long on that for the result >.<! But I learned a lot so I guess thats cool : /. I need to play with my stamp more often, granted pics are so much cheaper and better. ;)

P.S. This only works for BS2 on, BS1 users need to change some things.
 

RoyaL-TigeR

New Member
Java

Sorry, I don't know how you put thing inside a box like that.

________________


import java.util.Scanner;

public class HelloCF
{
public static void main (String[] args)
{
String name;
Scanner scan = new Scanner (System.in);

System.out.println ("Hi! What's your name?");
name = scan.nextLine();

System.out.println ("Hello " + name + "! Welcome to Computer Forum!");
}
}
 
Top