Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions C#_Exercise_Suite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
1.1.1. Write a console application (BasicVariables) that declares and initializes variables of appropriate data types with specified values.

● Declare variables using explicit types (int, double, bool, string, decimal) first.
● Refactor them to use the implicit typing keyword var.
● Challenge: Why does the C# compiler require an initialization value when using var? Write your answer as a multi-line comment at the top of your program.

● Required variables to declare:
o myAge initialized with your age.
o myHeight initialized with your height (e.g., 1.72).
o isPermanentResident initialized with your residency status (true/false).
o myNickname initialized with your nickname.
o myEstimatedNetWorth initialized with your estimated net worth.
o myLinkedIn initialized with your LinkedIn profile link.

1.1.2. In the BasicVariables program Display the values of these variables on the console with descriptive labels using Console.WriteLine() method.

1.1.3. In the BasicVariables program experiment with different formatting options
● Modify the height display using composite formatting ({0}, variable) format eg. ("Height is {0}", myHeight).
● Modify the name display utilizing explicit string concatenation (string + string)) eg. ("Nickname: " + myNickname).
● Modify the all others display line to string interpolation ($” {variable}”) format

1.2. Interactive User Input [Ref: MSDN - Console Input]

1.2.1. Modify the BasicVariables console application to prompt the user to enter all variables using Console.ReadLine().
● Ensure you parse the incoming string data to the appropriate type safely (e.g., using int.Parse(), double.Parse(), decimal.Parse(), or bool.Parse()).

1.3. Data Types and Casting [Ref: MSDN - Casting and Type Conversions]
1.3.1. Write a new program called (TypeAndCastCalculator) that performs arithmetic operations (addition +, division /) on two numeric (number1, number2) variables of type integer which entered by prompting user.

● Store the result of addition in a sum variable and the result of division in a quotient variable.
● Convert inputs using decimal.Parse() or convert integer elements explicitly.
● Ensure you handle integer division safely by applying an explicit inline type-cast ((double) or (decimal)) to prevent fractional truncation before processing.

1.4. ConstantVariables [Ref: MSDN - Constants]





40 changes: 40 additions & 0 deletions CSharpPractice.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhileLoopPassword", "WhileL
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdditionalWhileLoop", "AdditionalWhileLoop\AdditionalWhileLoop.csproj", "{2AED649B-AFFD-47B8-8B1B-D1A0F37E9508}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DoWhileLoopGuessNumber", "DoWhileLoopGuessNumber\DoWhileLoopGuessNumber.csproj", "{D5FE483D-8B47-4E9E-98C3-2726C61681DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DoWhileLoopRollDice", "DoWhileLoopRollDice\DoWhileLoopRollDice.csproj", "{FF9DF193-6302-4B0B-B835-AF439942A61F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DoWhileLoopAverageCalculator", "DoWhileLoopAverageCalculator\DoWhileLoopAverageCalculator.csproj", "{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiplicationNestedForLoop", "MultiplicationNestedForLoop\MultiplicationNestedForLoop.csproj", "{702ADB90-089C-49CF-8920-5543C6D50FC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarsTriangleNestedFor", "StarsTriangleNestedFor\StarsTriangleNestedFor.csproj", "{3BF25747-649B-49B0-AA1F-39601F662F45}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
ProjectSection(SolutionItems) = preProject
C#_Exercise_Suite.txt = C#_Exercise_Suite.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -271,6 +286,26 @@ Global
{2AED649B-AFFD-47B8-8B1B-D1A0F37E9508}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AED649B-AFFD-47B8-8B1B-D1A0F37E9508}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AED649B-AFFD-47B8-8B1B-D1A0F37E9508}.Release|Any CPU.Build.0 = Release|Any CPU
{D5FE483D-8B47-4E9E-98C3-2726C61681DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5FE483D-8B47-4E9E-98C3-2726C61681DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5FE483D-8B47-4E9E-98C3-2726C61681DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5FE483D-8B47-4E9E-98C3-2726C61681DB}.Release|Any CPU.Build.0 = Release|Any CPU
{FF9DF193-6302-4B0B-B835-AF439942A61F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF9DF193-6302-4B0B-B835-AF439942A61F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF9DF193-6302-4B0B-B835-AF439942A61F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF9DF193-6302-4B0B-B835-AF439942A61F}.Release|Any CPU.Build.0 = Release|Any CPU
{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23}.Release|Any CPU.Build.0 = Release|Any CPU
{702ADB90-089C-49CF-8920-5543C6D50FC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{702ADB90-089C-49CF-8920-5543C6D50FC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{702ADB90-089C-49CF-8920-5543C6D50FC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{702ADB90-089C-49CF-8920-5543C6D50FC5}.Release|Any CPU.Build.0 = Release|Any CPU
{3BF25747-649B-49B0-AA1F-39601F662F45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BF25747-649B-49B0-AA1F-39601F662F45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BF25747-649B-49B0-AA1F-39601F662F45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BF25747-649B-49B0-AA1F-39601F662F45}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -318,6 +353,11 @@ Global
{9907FB36-1145-4272-843C-01F030EF855C} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{240BC544-26C0-457D-A3FC-6AA46A8D2D19} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{2AED649B-AFFD-47B8-8B1B-D1A0F37E9508} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{D5FE483D-8B47-4E9E-98C3-2726C61681DB} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{FF9DF193-6302-4B0B-B835-AF439942A61F} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{F4909178-5FA6-48B1-ACBA-9F4F2EBDCF23} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{702ADB90-089C-49CF-8920-5543C6D50FC5} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
{3BF25747-649B-49B0-AA1F-39601F662F45} = {42676F42-8F68-4892-AAC5-C899BF2E2F8B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BD240BFE-F612-4D31-B438-DD8F1913314F}
Expand Down
25 changes: 24 additions & 1 deletion DoWhileLoopRollDice/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Console.WriteLine("=== Dice Roll Simulator ===");
Console.WriteLine("Rolling the die until we hit a 6...\n");

Random randomDice = new Random();
int rollCount = 0;
int currentRoll;


do
{

currentRoll = randomDice.Next(1, 7);

rollCount++;


Console.WriteLine($"Roll #{rollCount}: You rolled a [{currentRoll}]");

} while (currentRoll != 6);


Console.WriteLine("\n=============================================");
Console.WriteLine($"🎯 Success! It took a total of {rollCount} rolls to get a 6.");

}
}
}
10 changes: 10 additions & 0 deletions FactorialCalculator/FactorialCalculator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
10 changes: 10 additions & 0 deletions FactorialCalculator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FactorialCalculator
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
10 changes: 10 additions & 0 deletions PasswordRetryWhile/PasswordRetryWhile.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
28 changes: 28 additions & 0 deletions PasswordRetryWhile/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace PasswordRetryWhile
{
internal class Program
{
static void Main(string[] args)
{
string setPassword = "SecretPassword123";

string enteredPassword = string.Empty;

Console.WriteLine("=== Password Authentication Gateway ===");

while (enteredPassword != setPassword)
{
Console.Write("Enter the password: ");
enteredPassword = Console.ReadLine();

if (enteredPassword != setPassword)
{
Console.WriteLine("Incorrect password. Please try again.\n");
}
}


Console.WriteLine("Access Granted!");
}
}
}
26 changes: 26 additions & 0 deletions StarsTriangleNestedFor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace StarsTriangleNestedFor
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== Nested Loop Star Triangle ===\n");


int totalRows = 5;


for (int row = 1; row <= totalRows; row++)
{

for (int col = 1; col <= row; col++)
{

Console.Write("*");
}

Console.WriteLine();
}
}
}
}
10 changes: 10 additions & 0 deletions StarsTriangleNestedFor/StarsTriangleNestedFor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading