Skip to content

Commit f9b541e

Browse files
committed
FizzBuzz
- Add program lofic flowchart - Add pseudocode - Add try / catch block to catch exceptions - Add check number is a whole number - Add check number is not zero - Add FizzBzz Logic - Add code comments
1 parent 0b7825e commit f9b541e

21 files changed

+466
-2
lines changed
54 KB
Binary file not shown.

FizzBuzz/FizzBuzz/FizzBuzz.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.33529.622
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzz", "FizzBuzz\FizzBuzz.csproj", "{DBA82028-28B4-4B6C-89BE-76E0727EF260}"
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+
{DBA82028-28B4-4B6C-89BE-76E0727EF260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DBA82028-28B4-4B6C-89BE-76E0727EF260}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DBA82028-28B4-4B6C-89BE-76E0727EF260}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DBA82028-28B4-4B6C-89BE-76E0727EF260}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B8300AE4-9DC5-4FDC-8EF2-091656289D63}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{DBA82028-28B4-4B6C-89BE-76E0727EF260}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>FizzBuzz</RootNamespace>
10+
<AssemblyName>FizzBuzz</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
</Project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// FizzBuzz
2+
// by Steven Partlow
3+
// DATE: 01/06/2023
4+
5+
/* A C# version of the FizzBuzz problem, uses a TRY / CATCH block to exceptions, check that the number entered is a whole number with no
6+
decimal places , then checks for FizzBuzz (divisable by 3 and 5), Fizz (divisable by 3) and Buzz (divisable by 5) before a general message
7+
if none of those three apply, then the program ends */
8+
9+
using System;
10+
11+
namespace FizzBuzz
12+
{
13+
14+
class Program
15+
{
16+
17+
static void Main(string[] args)
18+
{
19+
while (true)
20+
{
21+
22+
double userNum; // Define variable userNum as a double data type
23+
try // Try this code, get the user to enter a whole number and catch any errors
24+
{
25+
// Output the following text to the console
26+
Console.WriteLine("FizzBuzz");
27+
Console.WriteLine("--------\n");
28+
29+
Console.Write("Please enter a WHOLE number: "); // Ask the user to enter a whole number
30+
userNum = Convert.ToDouble(Console.ReadLine()); // Take the inputted user string, convert to type int and store in variable userNum
31+
32+
bool isInt = userNum == (int)userNum; // Check if the number entered is a whole number with no decimal places
33+
if (isInt == false) // If it is not a whole number
34+
{
35+
Console.WriteLine("\nPlease enter a WHOLE, no decimal places, Please try again!.\n"); // Output this text to the console
36+
continue; // Restart the loop and get the user enter a number again
37+
} // End IF
38+
else if (userNum == 0)
39+
{
40+
Console.WriteLine("\nPlease do not enter a ZERO, Thank You!.\n"); // Output this text to the console
41+
continue; // Restart the loop and get the user enter a number again
42+
} // End ELSE IF
43+
44+
} // End TRY
45+
46+
catch (FormatException ex) // Catch the user attempting to enter a string instead of a number
47+
{
48+
Console.WriteLine("\nPlease enter a WHOLE number, no text, Thank You!.\n"); // Output this text to the console
49+
continue; // Restart the loop and get the user enter a number again
50+
} // End CATCH Format Exception
51+
52+
catch (DivideByZeroException ex) // Catch the user attempting to divide by zero
53+
{
54+
Console.WriteLine("\nPlease do not enter ZERO, Thank You!\n."); // Output this text to the console
55+
continue; // Restart the loop and get the user enter a number again
56+
} // End CATCH Divide by Zero Exception
57+
58+
catch (Exception ex) // Catch any other type of error
59+
{
60+
Console.WriteLine("\nThere was an error, please try again, Thank You!.\n"); // Output this text to the console
61+
continue; // Restart the loop and get the user enter a number again
62+
} // End CATCH General Exception
63+
64+
// End of CATCH Block
65+
66+
// FizzBuzz LOGIC
67+
if (userNum % 3 == 0 && userNum % 5 == 0) // If the the value the user entered is divisable by three and five then
68+
{
69+
Console.WriteLine("\nFizzBuzz"); // Output 'FizzBuzz' to the console
70+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
71+
Console.ReadKey(); // Peuse the application until the user presses a key
72+
break; // Break the WHILE loop
73+
} // End IF
74+
else if (userNum % 3 == 0) // If the the value the user entered is divisable by three then
75+
{
76+
Console.WriteLine("\nFizz"); // Output 'Fizz' to the console
77+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
78+
Console.ReadKey(); // Peuse the application until the user presses a key
79+
break; // Break the WHILE loop
80+
} // End ELSE IF
81+
else if (userNum % 5 == 0) // If the the value the user entered is divisable by five then
82+
{
83+
Console.WriteLine("\nBuzz"); // Output 'Buzz' to the console
84+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
85+
Console.ReadKey(); // Peuse the application until the user presses a key
86+
break; // Break the WHILE loop
87+
} // End ELSE IF
88+
else // If none of the the three condition above are met
89+
{
90+
Console.WriteLine("\nSorry not Fizz or Buzz :("); // Output this text to the console
91+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
92+
Console.ReadKey(); // Peuse the application until the user presses a key
93+
break; // Break the WHILE loop
94+
} // End ELSE
95+
96+
} //End WHILE
97+
98+
} // End MAIN Program
99+
100+
} // END Program CLASS
101+
102+
} // END FizzBuzz NAMESPACE
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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("FizzBuzz")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("FizzBuzz")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
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("dba82028-28b4-4b6c-89be-76e0727ef260")]
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")]
6 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
21.5 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

0 commit comments

Comments
 (0)