Skip to content

Commit 4569304

Browse files
authored
Add files via upload
Exercise - Complete a challenge activity using conditional operators
1 parent d1ad5ea commit 4569304

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Program.cs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
Console.WriteLine("a"=="a ");// This will return false surprisingly the space counts for the case of C#
6+
//Next we have the equality check that lets' users input values suchas Y or y as input and are accepted
7+
8+
string value1= " a";
9+
string value2= "A ";
10+
11+
//output
12+
Console.WriteLine(value1.Trim().ToLower() == value2.Trim().ToLower());
13+
14+
string text = "The lazy fox jumps over the duck";
15+
16+
Console.WriteLine(text.Contains("fox"));// This returns True for the case of string variables
17+
18+
int a = 5;
19+
int b =6;
20+
21+
Console.WriteLine(a!=b);// this reuturn true
22+
23+
int saleAmount = 1001;
24+
int discount = (saleAmount > 1000 )? 100 : 50;
25+
Console.WriteLine($"Discount: {discount}");
26+
int purchaseValue =1000;
27+
28+
//Discount
29+
int discount2 = purchaseValue >1000 ? 100 : 50 ;
30+
31+
//output
32+
Console.WriteLine($"Discount 2: {discount2}");
33+
34+
//Exercise - Complete a challenge activity using conditional operators
35+
// Conditional operator challenge
36+
// In this challenge, you'll implement a conditional operator to simulate a "coin flip".
37+
// The resulting decision logic will display either heads or tails.
38+
39+
Random coin = new Random();
40+
41+
int flip = coin.Next(0,2);
42+
//result from my conditional statm'nt
43+
string result = (flip == 0 )? "heads":"Tails";
44+
Console.WriteLine($"Result: {result}");
45+
46+
//Alright lets go logical with C#
47+
string permission = "Admin|Manager";
48+
int level = 60;
49+
//permision.Contains('Admin');
50+
if (level > 55)
51+
{
52+
Console.WriteLine("Welcome, Super Admin user.");
53+
}
54+
else if (level <= 55 && level >= 20)
55+
{
56+
Console.WriteLine("Welcome, Admin user.");
57+
}
58+
else if (level < 20)
59+
{
60+
Console.WriteLine("You do not have sufficient privileges.");
61+
}
62+
63+
// Check permissions if level is less than 55
64+
if (!permission.Contains("Admin") && !permission.Contains("Manager"))
65+
{
66+
Console.WriteLine("You do not have sufficient privileges.");
67+
}
68+
69+

0 commit comments

Comments
 (0)