Login
|
Signup
langref.org
-
cpp
and
csharp
add..
all
clojure
erlang
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Structure
Conditionals
Perform different actions depending on a boolean condition (IF .. THEN .. ELSE)
Given a variable age, if the value is greater than 42 display
"You are old"
, otherwise display
"You are young"
cpp
C++/CLI .NET 2.0
if (age > 42) Console::WriteLine("You are old");
else Console::WriteLine("You are young");
using namespace System;
int main()
{
int age = 42;
if (age > 42) Console::WriteLine("You are old");
else Console::WriteLine("You are young");
}
cpp
C++/CLI .NET 2.0
Console::WriteLine("You are {0}", (age > 42 ? "old" : "young"));
using namespace System;
int main()
{
int age = 42;
Console::WriteLine("You are {0}", (age > 42 ? "old" : "young"));
}
cpp
std::printf("You are %s\n", (age > 42 ? "old" : "young"));
int main()
{
int age = 42;
std::printf("You are %s\n", (age > 42 ? "old" : "young"));
}
csharp
int age = 41;
if (age > 42)
System.Console.WriteLine("You are old");
else
System.Console.WriteLine("You are young");
int age = 41;
if (age > 42)
System.Console.WriteLine("You are old");
else
System.Console.WriteLine("You are young");
Submit a new solution for
cpp
or
csharp
There are 31 other solutions in
additional
languages (
clojure
,
erlang
,
fantom
,
fsharp
...)