├── .gitattributes ├── .gitignore ├── CSharp for Beginners Exercises.sln ├── CSharp for Beginners Exercises ├── App.config ├── Arrays and Lists │ ├── DisplayUniqueNumbers.cs │ ├── FriendsWhoLikeYourPost.cs │ ├── ReverseGivenName.cs │ ├── SortFiveUniqueNumbers.cs │ └── ThreeSmallestNumbersInList.cs ├── CSharp for Beginners Exercises.csproj ├── CSharp for Beginners Exercises.sln ├── Control Flow │ ├── CarSpeedLimit.cs │ ├── DivisibleByThree.cs │ ├── FindFactorial.cs │ ├── FindMaxFromList.cs │ ├── GuessRandomNumber.cs │ ├── LandscapePortraitImage.cs │ ├── MaxTwoNumbers.cs │ ├── SumAllEnteredNumbers.cs │ └── ValidNumber.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Working with Files │ ├── LongestWordInFile.cs │ ├── NumberOfWordsInFile.cs │ └── words.txt └── Working with Text │ ├── ConsecutiveNumbers.cs │ ├── ConvertWordToPascalCase.cs │ ├── CountVowels.cs │ ├── FindDuplicate.cs │ └── ValidTimeRange.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | /CSharp for Beginners Exercises/Post.cs 244 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharp for Beginners Exercises", "CSharp for Beginners Exercises\CSharp for Beginners Exercises.csproj", "{4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Arrays and Lists/DisplayUniqueNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Arrays_and_Lists 6 | { 7 | /* 8 | * Write a program and ask the user to continously enter a number or type "Quite" 9 | * to exit. The list of numbers may include duplicates. Display the unique numbers 10 | * that the user has entered. 11 | */ 12 | internal static class DisplayUniqueNumbers 13 | { 14 | public static void Run() 15 | { 16 | Console.WriteLine("Enter whatever number you like or 'quit' to exit out and view the results"); 17 | 18 | var numbers = new List(); 19 | while (true) 20 | { 21 | var input = Console.ReadLine(); 22 | 23 | if (input != null && input.ToLower() == "quit") 24 | { 25 | var uniqueNumbers = GetUniqueNumbersList(numbers); 26 | uniqueNumbers.Sort(); 27 | uniqueNumbers.ForEach(Console.WriteLine); 28 | } 29 | else 30 | { 31 | numbers.Add(Convert.ToInt32(input)); 32 | } 33 | } 34 | } 35 | 36 | private static List GetUniqueNumbersList(IEnumerable numbers) 37 | { 38 | return numbers.GroupBy(number => number) 39 | .Where(number => number.Count() == 1) 40 | .SelectMany(number => number) 41 | .ToList(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Arrays and Lists/FriendsWhoLikeYourPost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CSharp_for_Beginners_Exercises.Arrays_and_Lists 5 | { 6 | /* 7 | * When you post a message on Facebook, depending on the number of people who like 8 | * your post, Facebook displays different information. 9 | * 10 | * If no one likes your post, it doesn't display anything. 11 | * 12 | * If only one person likes your post, it displays: [Friend's Name] likes your post. 13 | * 14 | * If two people like your post, it displays: [Friend 1] 15 | * and [Friend 2] like your post. 16 | * 17 | * If more than two people like your post, it displays: [Friend 1], [Friend 2] and 18 | * [Number of Other People] others like your post. 19 | * 20 | * Write a program and constinuously ask the user to enter a different name, until 21 | * the user presses ENTER (without supplying a name). Depending on the number of 22 | * names provided, display a message based on the above pattern. 23 | * 24 | */ 25 | internal static class FriendsWhoLikeYourPost 26 | { 27 | public static void Run() 28 | { 29 | var names = new List(); 30 | 31 | while (true) 32 | { 33 | var name = AskForName(); 34 | 35 | if (string.IsNullOrEmpty(name)) 36 | break; 37 | 38 | names.Add(name); 39 | Console.WriteLine(GetLikesMessage(names)); 40 | } 41 | } 42 | 43 | private static string AskForName() 44 | { 45 | Console.WriteLine("Enter a name: (Leave it empty to close the program)"); 46 | return Console.ReadLine(); 47 | } 48 | 49 | private static string GetLikesMessage(List names) 50 | { 51 | if (names.Count > 2) 52 | return names[0] + ", " + names[1] + " and " + GetExtraLikes(names).Count + " liked your post"; 53 | if (names.Count == 2) 54 | return names[0] + " and " + names[1] + " liked your post"; 55 | 56 | return names[0] + " liked your post"; 57 | } 58 | 59 | private static List GetExtraLikes(List names) 60 | { 61 | return names.GetRange(2, names.Count - 2); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Arrays and Lists/ReverseGivenName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Arrays_and_Lists 6 | { 7 | /* 8 | * Write a program and ask the user to enter their name. 9 | * Use an array to reverse the name and then store the result in a new String. 10 | * 11 | * Display the reversed name on the console. 12 | */ 13 | internal static class ReverseGivenName 14 | { 15 | public static void Run() 16 | { 17 | Console.WriteLine("Enter the name you wish to reverse: "); 18 | var name = Console.ReadLine(); 19 | var reversedName = GetReversedName(name); 20 | 21 | Console.WriteLine("The name {0} gets reversed to {1}", name, reversedName); 22 | } 23 | 24 | private static string GetReversedName(string name) 25 | { 26 | var list = name.ToList(); 27 | list.Reverse(); 28 | 29 | return string.Join("", list.ToArray()); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Arrays and Lists/SortFiveUniqueNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CSharp_for_Beginners_Exercises.Arrays_and_Lists 5 | { 6 | /* 7 | * Write a program and ask the user to enter 5 numbers. 8 | * 9 | * If a number has been previously entered, display an error message 10 | * and ask the user to re-try. 11 | * 12 | * Once the user successfully enters 5 unique numbers, sort them and display 13 | * the result on the console. 14 | */ 15 | internal static class SortFiveUniqueNumbers 16 | { 17 | public static void Run() 18 | { 19 | Console.WriteLine("Enter 5 unique numbers"); 20 | const int uniqueAmount = 5; 21 | 22 | var numbers = new List(); 23 | while (true) 24 | { 25 | Console.WriteLine("Your number is: "); 26 | var number = Convert.ToInt32(Console.ReadLine()); 27 | 28 | if (numbers.Contains(number)) 29 | Console.WriteLine("Provide a number that hasn't been used before"); 30 | else 31 | numbers.Add(number); 32 | 33 | if (numbers.Count == uniqueAmount) continue; 34 | numbers.Sort(); 35 | break; 36 | } 37 | 38 | numbers.ForEach(Console.WriteLine); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Arrays and Lists/ThreeSmallestNumbersInList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Arrays_and_Lists 6 | { 7 | /* 8 | * Write a program and ask the user to supply a list of coma separated numbers 9 | * (e.g. 5, 1, 9, 2, 10). 10 | * 11 | * If the list is empty or includes less than 5 numbers, display "Invalid List" 12 | * and ask the user to re-try; otherwise, display the 3 smallest numbers in the list. 13 | */ 14 | internal static class ThreeSmallestNumbersInList 15 | { 16 | public static void Run() 17 | { 18 | Console.WriteLine("Enter a list of numbers separated by commas: "); 19 | var input = Console.ReadLine(); 20 | 21 | if (string.IsNullOrEmpty(input)) 22 | Console.WriteLine("The list cannot be empty or null. Please retry"); 23 | else 24 | { 25 | var numbers = GetNumbersListSeparatedByComa(input); 26 | numbers.Sort(); 27 | if (numbers.Count < 5) 28 | Console.WriteLine("Invalid list, has less than 5 numbers. Please retry."); 29 | else 30 | { 31 | var smallestThreeNumbers = new List(); 32 | for (var i = 0; i < 3; i++) 33 | smallestThreeNumbers.Add(numbers[i]); 34 | 35 | smallestThreeNumbers.ForEach(Console.WriteLine); 36 | } 37 | } 38 | } 39 | 40 | private static List GetNumbersListSeparatedByComa(string input) 41 | { 42 | return input.Split((',')).Select(s => Convert.ToInt32(s.Trim())).ToList(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/CSharp for Beginners Exercises.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE} 8 | Exe 9 | Properties 10 | CSharp_for_Beginners_Exercises 11 | CSharp for Beginners Exercises 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 84 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/CSharp for Beginners Exercises.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharp for Beginners Exercises", "CSharp for Beginners Exercises.csproj", "{4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {4C6F1D7A-E3F7-47F9-B7A8-0D28B7DC20EE}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/CarSpeedLimit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Your job is to write a program for a speed camera. 7 | * 8 | * For simplicity, ignore the details such as camera, sensors, etc and focus purely on the logic. 9 | * 10 | * Write a program that asks the user to enter the speed limit. 11 | * 12 | * Once set, the program asks for the speed of a car. 13 | * 14 | * If the user enters a value less than the speed limit, program should dispplay OK on the console. 15 | * 16 | * If the value is above the speed limit, the program should calculate the number of demerit points. 17 | * 18 | * For every 5km/hr above the speed limit, 1 demerit poinst should be incurred and displayed on the console. 19 | * 20 | * If the number of demerit poinst is above 12, the program should display License Suspended. 21 | */ 22 | internal static class CarSpeedLimit 23 | { 24 | public static void Run() 25 | { 26 | Console.WriteLine("Enter the speed limit value: "); 27 | var speedLimit = Convert.ToInt32(Console.ReadLine()); 28 | 29 | Console.WriteLine("Enter the speed of the car"); 30 | var carSpeed = Convert.ToInt32(Console.ReadLine()); 31 | 32 | if (carSpeed > speedLimit) 33 | { 34 | var demeritPoints = 0; 35 | while (carSpeed > speedLimit) 36 | { 37 | carSpeed -= 5; 38 | demeritPoints++; 39 | } 40 | 41 | if (demeritPoints > 12) 42 | Console.WriteLine("License Suspended."); 43 | } 44 | else 45 | { 46 | Console.WriteLine("OK"); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/DivisibleByThree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program to count how many numbers between 1 and 100 are divisible by 3 with no remainder. 7 | * Display the count on the console. 8 | */ 9 | internal static class DivisibleByThree 10 | { 11 | public static void Run() 12 | { 13 | Console.WriteLine("How many numbers are divisible by 3? {0}", CountNumbersDivisibleByThree()); 14 | } 15 | 16 | private static int CountNumbersDivisibleByThree() 17 | { 18 | var count = 0; 19 | for (var i = 1; i <= 100; i++) 20 | if (i % 3 == 0) count++; 21 | 22 | return count; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/FindFactorial.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program and ask the user to enter a number. Compute the factorial of the number 7 | * and print it on the console. For example, if the user enters 5, the programs should 8 | * calculate 5 x 4 x 3 x 2 x 1 and display it as 5! = 120 9 | */ 10 | internal static class FindFactorial 11 | { 12 | public static void Run() 13 | { 14 | Console.WriteLine("Type in the number to find it's factorial: "); 15 | var number = Convert.ToInt32(Console.ReadLine()); 16 | 17 | Console.WriteLine("{0}! = {1}", number, Factorial(number)); 18 | } 19 | 20 | private static int Factorial(int number) 21 | { 22 | if (number == 0 || number == 1) 23 | return 1; 24 | 25 | return number * Factorial(number - 1); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/FindMaxFromList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Control_Flow 6 | { 7 | /* 8 | * Write a program and ask the user to enter a series of numbers separated by coma. 9 | * Find the maximum of the numbers and display it on the console. 10 | * For example, if the user enters "5, 3, 8, 1, 4", the program should display 8. 11 | */ 12 | internal static class FindMaxFromList 13 | { 14 | public static void Run() 15 | { 16 | Console.WriteLine("Enter a series of numbers seperated by commas (Example: 1, 2, 3)"); 17 | var input = Console.ReadLine(); 18 | var numbers = GetListFromValuesSeparatedWithCommas(input); 19 | var max = numbers?.Max(); 20 | 21 | Console.WriteLine("The maximum number is: " + max); 22 | } 23 | 24 | private static IEnumerable GetListFromValuesSeparatedWithCommas(string input) 25 | { 26 | return input?.Split(',').Select(number => Convert.ToInt32(number.Trim())).ToList(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/GuessRandomNumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program that picks a random number between 1 and 10. 7 | * Give the user 4 chances to guess the number. 8 | * If the user guesses the number, display "You won"; otherwise, display "You lost". 9 | * (To make sure the program is behaving correctly, yo can display the secret number 10 | * on console first.) 11 | */ 12 | internal static class GuessRandomNumber 13 | { 14 | public static void Run() 15 | { 16 | Console.WriteLine("Try to guess a number from 1 to 10. You have 4 chances"); 17 | var randomNumber = GenerateRandomNumber(); 18 | AttemptToGuess(randomNumber); 19 | } 20 | 21 | private static int GenerateRandomNumber() 22 | { 23 | var random = new Random(); 24 | return random.Next(1, 10); 25 | } 26 | 27 | private static void AttemptToGuess(int randomNumber) 28 | { 29 | for (var i = 0; i < 4; i++) 30 | { 31 | Console.Write("Try #{0}: ", i); 32 | var answer = Convert.ToInt32(Console.ReadLine()); 33 | 34 | if (answer == randomNumber) 35 | { 36 | Console.WriteLine("You won!"); 37 | break; 38 | } 39 | 40 | if (IsOutOfTries(i)) 41 | { 42 | Console.WriteLine("You lost. Ran out of tries."); 43 | break; 44 | } 45 | 46 | Console.WriteLine("Wrong guess, try again!"); 47 | } 48 | } 49 | 50 | private static bool IsOutOfTries(int i) 51 | { 52 | return i == 3; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/LandscapePortraitImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program and ask the user to enter the width and height of an image. 7 | * Then tell if the image is landscape or portrait. 8 | */ 9 | internal static class LandscapePortraitImage 10 | { 11 | public static void Run() 12 | { 13 | Console.WriteLine("Type in the width of an image to know if it is on Landscape or Portrait:"); 14 | 15 | Console.WriteLine("Width: "); 16 | var width = Convert.ToInt32(Console.ReadLine()); 17 | 18 | Console.WriteLine("Height: "); 19 | var heigth = Convert.ToInt32(Console.ReadLine()); 20 | 21 | Console.WriteLine(GetImageOrientation(width, heigth)); 22 | } 23 | 24 | private static string GetImageOrientation(int width, int heigth) 25 | { 26 | if (width == heigth) 27 | return "Both values are the same. The image has a 1:1 ratio"; 28 | if (width > heigth) 29 | return "Landscape"; 30 | 31 | return "Portrait"; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/MaxTwoNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | // Write a program which takes two numbers from the console and displays the maximum of the two. 6 | internal static class MaxTwoNumbers 7 | { 8 | public static void Run() 9 | { 10 | Console.WriteLine("Type in 2 numbers (separated by space)to be compared to know which one is the highest"); 11 | 12 | Console.WriteLine("First number: "); 13 | var firstNumber = Convert.ToInt32(Console.ReadLine()); 14 | 15 | Console.WriteLine("Second number: "); 16 | var secondNumber = Convert.ToInt32(Console.ReadLine()); 17 | 18 | if (firstNumber == secondNumber) 19 | Console.WriteLine("The provided values are the same"); 20 | else 21 | Console.WriteLine("Between {0} and {1}, the highest number is: {2}", firstNumber, secondNumber, 22 | GetHighestNumber(firstNumber, secondNumber)); 23 | } 24 | 25 | private static int GetHighestNumber(int firstNumber, int secondNumber) 26 | { 27 | return (firstNumber > secondNumber) ? firstNumber : secondNumber; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/SumAllEnteredNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program and continously ask the user to enter a number or "ok" to exit. 7 | * Calculate the sum of all the previously entered numbers and siplay it on the console. 8 | */ 9 | internal static class SumAllEnteredNumbers 10 | { 11 | public static void Run() 12 | { 13 | var sum = 0; 14 | while (true) 15 | { 16 | Console.WriteLine("Enter a number: "); 17 | var input = Console.ReadLine(); 18 | 19 | if (input == "ok") 20 | break; 21 | 22 | var number = Convert.ToInt32(input); 23 | 24 | sum += number; 25 | } 26 | 27 | Console.WriteLine("Sum of all the numbers is: {0}", sum); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Control Flow/ValidNumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Control_Flow 4 | { 5 | /* 6 | * Write a program and ask the user to enter a number. The number should be between 1 to 10. 7 | * If the user en ters a valid number, display "Valid" on the console. Otherwise, display "Invalid". 8 | * (This logic is used a lot in applications where values entered into input boxes need to be validadted.) 9 | */ 10 | internal class ValidNumber 11 | { 12 | public void Run() 13 | { 14 | Console.WriteLine("Enter a number between 1 to 10"); 15 | var number = Convert.ToInt32(Console.ReadLine()); 16 | 17 | Console.WriteLine(IsBetweenOneToTen(number) ? "Valid" : "Invalid"); 18 | } 19 | 20 | private static bool IsBetweenOneToTen(int number) 21 | { 22 | return number >= 1 && number <= 10; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Program.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp_for_Beginners_Exercises 2 | { 3 | internal class Program 4 | { 5 | public static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CSharp for Beginners Exercises")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CSharp for Beginners Exercises")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4c6f1d7a-e3f7-47f9-b7a8-0d28b7dc20ee")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Files/LongestWordInFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Working_with_Files 6 | { 7 | // Write a program that reads a file and displays the longest word in the file. 8 | public static class LongestWordInFile 9 | { 10 | public static void Run() 11 | { 12 | var text = ReadFileToString("/Users/christianvasquez/RiderProjects/" + 13 | "udemy-csharp-beginners/CSharp for Beginners Exercises/" + 14 | "Working with Files/words.txt"); 15 | var words = text.Split(' '); 16 | var longestWord = ""; 17 | foreach (var word in words) 18 | { 19 | if (longestWord.Length < word.Length) 20 | longestWord = word; 21 | } 22 | Console.WriteLine("The longest word in the word.txt file is: " + longestWord); 23 | } 24 | 25 | private static string ReadFileToString(string filePath) 26 | { 27 | using (var streamReader = new StreamReader(@"" + filePath + "", Encoding.UTF8)) 28 | return streamReader.ReadToEnd(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Files/NumberOfWordsInFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Working_with_Files 6 | { 7 | // Write a program that reads a text file and displays the number of words. 8 | public class NumberOfWordsInFile 9 | { 10 | public static void Run() 11 | { 12 | var text = ReadFileToString("/Users/christianvasquez/RiderProjects/udemy-csharp-beginners/" + 13 | "CSharp for Beginners Exercises/Working with Files/words.txt"); 14 | var words = text.Split(' '); 15 | Console.WriteLine("The word.txt file has {0} words inside it", words.Length); 16 | } 17 | 18 | private static string ReadFileToString(string filePath) 19 | { 20 | using (var streamReader = new StreamReader(@"" + filePath + "", Encoding.UTF8)) 21 | return streamReader.ReadToEnd(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Files/words.txt: -------------------------------------------------------------------------------- 1 | This is a test file for the Working with Files set of exercises. -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Text/ConsecutiveNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Working_with_Text 6 | { 7 | /* 8 | * Write a program and ask the user to enter a few numbers separated by a hyphon. 9 | * Workout if the numbers are consecutive. For example, if the input is "5-6-7-8-9" 10 | * or "20-19-18-17-16", display a message: "Consecutive"; otherwise, display 11 | * "Not-Consecutive". 12 | */ 13 | internal static class ConsecutiveNumbers 14 | { 15 | public static void Run() 16 | { 17 | Console.WriteLine("Enter a list of numbers separated by '-'"); 18 | var answer = Console.ReadLine(); 19 | var numbers = GetNumbersWithoutHyphon(answer); 20 | Console.WriteLine(IsConsecutive(numbers) ? "Consecutive" : "Not Consecutive"); 21 | } 22 | 23 | private static List GetNumbersWithoutHyphon(string answer) 24 | { 25 | return answer?.Split('-').Select(number => Convert.ToInt32(number)).ToList(); 26 | } 27 | 28 | private static bool IsConsecutive(List numbers) 29 | { 30 | var firstNumber = numbers[0]; 31 | var secondNumber = numbers[1]; 32 | var temporalNumber = firstNumber; 33 | var countConsecutives = 1; 34 | if (IsAscending(firstNumber, secondNumber)) 35 | { 36 | foreach (var number in numbers) 37 | { 38 | if (IsAscending(temporalNumber, number)) 39 | { 40 | temporalNumber = number; 41 | countConsecutives++; 42 | } 43 | } 44 | } 45 | else 46 | { 47 | foreach (var number in numbers) 48 | { 49 | if (IsDescending(temporalNumber, number)) 50 | { 51 | temporalNumber = number; 52 | countConsecutives++; 53 | } 54 | } 55 | } 56 | 57 | return numbers.Count == countConsecutives; 58 | } 59 | 60 | private static bool IsAscending(int current, int next) 61 | { 62 | return current - next == -1; 63 | } 64 | 65 | private static bool IsDescending(int current, int next) 66 | { 67 | return current - next == 1; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Text/ConvertWordToPascalCase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace CSharp_for_Beginners_Exercises.Working_with_Text 5 | { 6 | /* 7 | * Write a program and ask the user to enter a few words separated by a space. 8 | * Use the words to create a variable name with PascalCase. For example, 9 | * if the user types: "number of students". display "NumberOfStudents". 10 | * Make sure that the program is not dependent on the input. So, if the user 11 | * types "NUMBER OF STUDENTS", the program should still display "NumberOfStudents". 12 | */ 13 | public static class ConvertWordToPascalCase 14 | { 15 | public static void Run() 16 | { 17 | Console.WriteLine("Type in any word/phrase to be converted to PascalCase"); 18 | var input = Console.ReadLine(); 19 | 20 | if (String.IsNullOrEmpty(input)) 21 | throw new ArgumentException("Null, whitespaces or empty are not allowed."); 22 | 23 | var words = input.Split(' ') 24 | .Select(word => word.Trim().ToLower()) 25 | .ToArray(); 26 | 27 | Console.WriteLine("PascalCased: " + ConvertToPascalCase(words)); 28 | } 29 | 30 | private static string ConvertToPascalCase(string[] words) 31 | { 32 | if (!words.Any()) 33 | throw new ArgumentException("Array or List has no elements."); 34 | 35 | var pascaled = ""; 36 | foreach (var word in words) 37 | pascaled += CapitalizeFirstLetter(word); 38 | 39 | return pascaled; 40 | } 41 | 42 | private static string CapitalizeFirstLetter(string word) 43 | { 44 | if (String.IsNullOrWhiteSpace(word)) 45 | return string.Empty; 46 | 47 | var letters = word.ToCharArray(); 48 | letters[0] = char.ToUpper(letters[0]); 49 | 50 | return new string(letters); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Text/CountVowels.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace CSharp_for_Beginners_Exercises.Working_with_Text 5 | { 6 | /* 7 | * Write a program and ask the enter an English word. Count the number of vowels 8 | * (a, e, i, o, u) in the word. So, if the user enters "inadequate", the program 9 | * should display 6 in the console. 10 | */ 11 | public static class CountVowels 12 | { 13 | public static void Run() 14 | { 15 | Console.WriteLine("Type in a word you wish to know how many vowels has:"); 16 | var input = Console.ReadLine(); 17 | 18 | Console.WriteLine("The word '{0}' has {1} vowels", input, CountVowelsInWord(input)); 19 | } 20 | 21 | private static int CountVowelsInWord(string word) 22 | { 23 | var counter = 0; 24 | char[] vowels = {'a', 'e', 'i', 'o', 'u'}; 25 | foreach (var letter in word) 26 | { 27 | if (vowels.Contains(letter)) 28 | counter++; 29 | } 30 | 31 | return counter; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Text/FindDuplicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace CSharp_for_Beginners_Exercises.Working_with_Text 6 | { 7 | /* 8 | * Write a program and ask the user to enter a few numbers separated by a hyphen. 9 | * If the user simply presses Enter, without supplying any input, exit immediately; 10 | * otherwise, check to see if there are duplicates. 11 | * 12 | * If so, display "Duplicate" on the console. 13 | */ 14 | internal static class FindDuplicate 15 | { 16 | public static void Run() 17 | { 18 | Console.WriteLine("Enter a series of numbers separated by '-'"); 19 | var answer = Console.ReadLine(); 20 | 21 | if (string.IsNullOrWhiteSpace(answer)) 22 | Environment.Exit(0); 23 | 24 | var numbers = answer.Split('-').Select(number => Convert.ToInt32(number)).ToList(); 25 | 26 | Console.WriteLine(HasAnyDuplicate(numbers) ? "Has duplicates" : "No duplicates were found"); 27 | } 28 | 29 | private static bool HasAnyDuplicate(List numbers) 30 | { 31 | return numbers.GroupBy(number => number).Any(duplicate => duplicate.Count() > 1); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CSharp for Beginners Exercises/Working with Text/ValidTimeRange.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CSharp_for_Beginners_Exercises.Working_with_Text 4 | { 5 | /* 6 | * Write a program and ask the user to enter a time value in the 24 hour time format 7 | * (e.g. 19:00). A valid time should be between 00:00 and 23:59. If the time is valid, 8 | * display "Ok"; otherwise, display "Invalid Time". 9 | * 10 | * If the user doesn't provide any values, consider it as invalid time. 11 | */ 12 | public static class ValidTimeRange 13 | { 14 | public static void Run() 15 | { 16 | Console.WriteLine("Type in a time value between 00:00 and 23:59"); 17 | var input = Console.ReadLine(); 18 | if (string.IsNullOrWhiteSpace(input)) 19 | { 20 | Console.WriteLine("Invalid Time"); 21 | } 22 | else 23 | { 24 | var hour = Convert.ToInt32(input?.Split(':')[0]); 25 | var minute = Convert.ToInt32(input?.Split(':')[1]); 26 | 27 | if (IsValidHour(hour) && IsValidMinute(minute)) 28 | Console.WriteLine("Ok"); 29 | else 30 | Console.WriteLine("Invalid Time"); 31 | } 32 | } 33 | 34 | private static bool IsValidHour(int hour) 35 | { 36 | return hour >= 0 && hour <= 23; 37 | } 38 | 39 | private static bool IsValidMinute(int minute) 40 | { 41 | return minute >= 0 && minute <= 59; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C# Basics for Beginners's Exercises 2 | Sample code for all the exercises from the [C# Basics for Beginners](https://www.udemy.com/csharp-tutorial-for-beginners/learn/v4/overview) 3 | course made by [Mosh Hamedani](https://github.com/mosh-hamedani) on [Udemy](https://www.udemy.com/). 4 | 5 | ## Section 5 - Control Flow 6 | 7 | In this section you will learn how to use **conditional statements** (_if-else_ & _switch-cases_) and **iteration statements** 8 | (_for_, _foreach_ & _while_). 9 | 10 | ### [ValidNumber.cs](https://goo.gl/g943yz) 11 | 12 | Write a program and ask the user to enter a number. The number should be between 1 to 10. If the user enters a valid 13 | number, display "Valid" on the console. Otherwise, display "Invalid". (This logic is used a lot in applications where 14 | values entered into input boxes need to be validated). 15 | 16 | ### [MaxTwoNumbers.cs](https://goo.gl/qogfd7) 17 | 18 | Write a program which takes two numbers from the console and displays the maximum of the two. 19 | 20 | ### [LandscapePortraitImage.cs](https://goo.gl/3EPrZX) 21 | 22 | Write a program and ask the user to enter the width and height of an image. Then tell if the image is landscape or portrait. 23 | 24 | ### [CarSpeedLimit.cs](https://goo.gl/TNQfRN) 25 | 26 | Your job is to write a program for a speed camera. For simplicity, ignore the details such as camera, sensors, etc and 27 | focus purely on the logic. Write a program that asks the user to enter the speed limit. Once set, the program asks for 28 | the speed of a car. If the user enters a value less than the speed limit, program should display Ok on the console. 29 | If the value is above the speed limit, the program should calculate the number of demerit points. For every 5km/hr 30 | above the speed limit, 1 demerit points should be incurred and displayed on the console. If the number of demerit points 31 | is above 12, the program should display License Suspended. 32 | 33 | ### [DivisibleByThree.cs](https://goo.gl/nWsmfY) 34 | 35 | Write a program to count how many numbers between 1 and 100 are divisible by 3 with no remainder. Display the count on 36 | the console. 37 | 38 | ### [SumAllEnteredNumbers.cs](https://goo.gl/APLPT9) 39 | 40 | Write a program and continuously ask the user to enter a number or "ok" to exit. Calculate the sum of all the previously 41 | entered numbers and display it on the console. 42 | 43 | ### [FindFactorial.cs](https://goo.gl/bTwHVN) 44 | 45 | Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console. 46 | For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5! = 120. 47 | 48 | ### [GuessRandomNumber.cs](https://goo.gl/PxAZ7r) 49 | 50 | Write a program that picks a random number between 1 and 10. Give the user 4 chances to guess the number. If the user 51 | guesses the number, display “You won"; otherwise, display “You lost". (To make sure the program is behaving correctly, 52 | you can display the secret number on the console first). 53 | 54 | ### [FindMaxFromList.cs](https://goo.gl/cLa9nA) 55 | 56 | Write a program and ask the user to enter a series of numbers separated by comma. Find the maximum of the numbers and 57 | display it on the console. For example, if the user enters “5, 3, 8, 1, 4", the program should display 8. 58 | 59 | ## Section 6 - Arrays and Lists 60 | 61 | This section is focused on how Arrays and Lists work, what are their similarities and differences, and use cases. 62 | 63 | ### [FriendsWhoLikeYourPost.cs](https://goo.gl/1fqsCc) 64 | 65 | When you post a message on Facebook, depending on the number of people who like your post, Facebook displays different information. 66 | 67 | - If no one likes your post, it doesn't display anything. 68 | - If only one person likes your post, it displays: [Friend's Name] likes your post. 69 | - If two people like your post, it displays: [Friend 1] and [Friend 2] like your post. 70 | - If more than two people like your post, it displays: [Friend 1], [Friend 2] and [Number of Other People] others like your post. 71 | 72 | Write a program and continuously ask the user to enter different names, until the user presses Enter (without supplying 73 | a name). Depending on the number of names provided, display a message based on the above pattern. 74 | 75 | ### [ReverseGivenName.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Arrays%20and%20Lists/ReverseGivenName.cs) 76 | 77 | Write a program and ask the user to enter their name. Use an array to reverse the name and then store the result in a 78 | new string. Display the reversed name on the console. 79 | 80 | ### [SortFiveUniqueNumbers.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Arrays%20and%20Lists/SortFiveUniqueNumbers.cs) 81 | 82 | Write a program and ask the user to enter 5 numbers. If a number has been previously entered, display an error message 83 | and ask the user to re-try. Once the user succesfully enters 5 unique numbers, sort them and display the result on the 84 | console. 85 | 86 | ### [ThreeSmallestNumbersInList.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Arrays%20and%20Lists/ThreeSmallestNumbersInList.cs) 87 | 88 | Write a pgram and ask the user to supply a list of coma separated numbers (e.g. 5, 1, 9, 2, 10). If the list is empty 89 | or includes less than 5 numbers, disply "Invalid List" and ask the user to re-try; otherwise, display the 3 smallest 90 | numbers in the list. 91 | 92 | ### [DisplayUniqueNumbers.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Arrays%20and%20Lists/DisplayUniqueNumbers.cs) 93 | 94 | Write a program and ask the user to continously enter a number or type "Quit" to exit. The list of numbers may include 95 | duplicates. Display the unique numbers that the user has entered. 96 | 97 | ## Section 8 - Working with Text 98 | 99 | In this section you will be capturing user's input from the console and then performing operations on that same data 100 | (like using the .Split() method to organize the data given, performing certain validation upon it and then outputting 101 | a result). 102 | 103 | ### [ConsecutiveNumbers.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Text/ConsecutiveNumbers.cs) 104 | 105 | Write a program and ask the user to enter a few numbers separated by a hyphon. Workout if the numbers are consecutive. 106 | For example, if the input is "5-6-7-8-9" or "20-19-17-16", display a message: "Consecutive"; otherwise, display 107 | "Not-Consecutive". 108 | 109 | ### [FindDuplicate.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Text/FindDuplicate.cs) 110 | 111 | Write a program and ask the user to enter a few numbers separated by a hyphen. If the user simply presses ENTER, without 112 | supplying any input, exit immediately; otherwise, check to see if there are dulicates. If so, display "Duplicate" on the 113 | console. 114 | 115 | ### [ValidTimeRange.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Text/ValidTimeRange.cs) 116 | 117 | Write a program and ask the user to enter a time value in the 24 hour time format (e.g. 19:00). A valid time should be 118 | between 00:00 and 23:59. If the time is valid, display "Ok"; otherwise, display "Invalid Time". IF the user doesn't 119 | provide any values, consider it as invalid time. 120 | 121 | ### [ConvertWordToPascalCase.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Text/ConvertWordToPascalCase.cs) 122 | 123 | Write a program and ask the user to enter a few words separated by a space. Ue the words to create a variable name with 124 | PascalCase. For example, if the user types: "number of students", display "NumberOfStudents". Make sure that the program 125 | is not dependent on the input. So, if the user types "NUMBER OF STUDENTS", the program should still display 126 | "NumberOfStudents". 127 | 128 | ### [CountVowels.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Text/CountVowels.cs) 129 | 130 | Write a program and ask it to enter an English word. Count the nunber of vowels (a, e, i, o, u) in the word. So, if the 131 | user enters "inadequate", the program should display 6 in the console. 132 | 133 | ## Section 9 - Working with Files 134 | 135 | In this section we will be reading the text content of a file that is in the same directory as each exercise 136 | (.../Working with Files/words.txt). 137 | 138 | ### [NumberOfWordsInFile.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Files/NumberOfWordsInFile.cs) 139 | 140 | Write a program that reads a text file and displays the number of words. 141 | 142 | ### [LongestWordInFile.cs](https://github.com/chrisvasqm/csharp-beginners/blob/master/CSharp%20for%20Beginners%20Exercises/Working%20with%20Files/LongestWordInFile.cs) 143 | 144 | Write a program that reads a file and displays the longest word in the file. 145 | --------------------------------------------------------------------------------