SIMPLE AND COMPLEX CONDITIONALS
//These are libraries from which you can get additional commands for your program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Class1
{
//This is the program where all our code will be...
internal class Program
{
//This is the main static function... this is important,
///because it is the core of our program, without it, the program will not work.
static void Main(string[] args)
{
//code
//Conditional statements:
// && is AND
// || is OR
//If the result is equal to 1
if (result == 1)
{
//Print the following message:
Console.WriteLine("Result is 1");
}
//Otherwise:
else
{
//Execute this code:
Console.WriteLine("Result is not 1");
}
//Now let's consider something more complex:
Console.WriteLine("Enter your name:");
string name = Console.ReadLine(); //We store the name in our variable...
Console.WriteLine("Please enter your age: ");
int age = int.Parse(Console.ReadLine()); //We store the integer age in our variable...
//Greater than (>) and less than (<) signs
if (age > 18)
{
Console.WriteLine(name + " is an adult");
}
//Otherwise:
else
{
Console.WriteLine("Not an adult");
}
/*Another case:*/
// Create a Random class object to generate random numbers
Random random = new Random();
// Generate a random integer from 0 to 99 (inclusive)
int randomNumber = random.Next(100);
Console.WriteLine("Random integer from 0 to 99: " + randomNumber);
// Generate a random integer in the range from 1 to 10
int randomRange = random.Next(1, 11);
Console.WriteLine("Random integer from 1 to 10: " + randomRange);
// Generate a random floating-point number from 0.0 to 1.0
double randomDouble = random.NextDouble();
Console.WriteLine("Random floating-point number from 0.0 to 1.0: " + randomDouble);
// Generate a random floating-point number in a given range (e.g., from 1.5 to 5.5)
double randomDoubleInRange = 1.5 + random.NextDouble() * (5.5 - 1.5);
Console.WriteLine("Random floating-point number from 1.5 to 5.5: " + randomDoubleInRange);
Console.ReadKey();
}
}
}