-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
140 lines (104 loc) · 3.93 KB
/
Program.cs
File metadata and controls
140 lines (104 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace palindrometest2
{
public class Program
{
static void ValidationCheck(ref string t1)
{
//string t2 = t1;
//Console.WriteLine("debug// String is: " + t1);
if (t1 == "")
{
Console.WriteLine("String cannot be empty.");
}
else
{
//exit function back to main
}
}
static void TestPalindrome(ref string testP)
{
//split char's into array of two
//test each position in array matches the other
//if it does return palindrome
//if it does not return try another word
var chars1 = testP.ToCharArray();
var chars2 = testP.ToCharArray();
//reverse string into var's for testing
//reverse chars2 so it can be tested
Array.Reverse(chars2);
/*
//debug start
Console.WriteLine("Original string: " + testP);
Console.WriteLine("Character array:");
for (int ctr = 0; ctr < chars1.Length; ctr++)
{
Console.WriteLine(" {" + ctr + "} " + chars1[ctr]);
}
//debug end
*/
//test the character arrays to see if they match
int endWhile = chars1.Length-1;
int n = 0;
int pal = 0;
//Console.WriteLine(endWhile);
for (n = 0; n < chars1.Length; n++)
{
if(chars1[n] == chars2[n])
{
//characters are the same then continue
//Console.WriteLine("char1= " + chars1[n] + " chars2= " + chars2[n]);
pal++;
}
else
{
Console.WriteLine("This is not a palindrome, your entry was: " + testP);
Console.WriteLine("It's characters were...");
Console.WriteLine("Forward:");
for (n = 0; n < chars1.Length; n++)
{
Console.WriteLine("char1= " + chars1[n]);
}
Console.WriteLine("Backward:");
for (n = 0; n < chars2.Length; n++)
{
Console.WriteLine("char2= " + chars2[n]);
}
}
}
if(pal == chars1.Length)
{
Console.WriteLine("This is a palindrome and your entry was: " + testP);
Console.WriteLine("It's characters were...");
Console.WriteLine("Forward:");
for (n = 0; n < chars1.Length; n++)
{
Console.WriteLine("char1= " + chars1[n]);
}
Console.WriteLine("Backward:");
for (n = 0; n < chars2.Length; n++)
{
Console.WriteLine("char2= " + chars2[n]);
}
}
}
//scope public // static means? // return value // function name // paramaters
static void Main()
{
string strInput = "nothing";
Console.WriteLine("Please enter a Palindrome to test.");
strInput = Console.ReadLine();
ValidationCheck(ref strInput);
//flatten capitalisation of string
string strFlatten = "flat";
strFlatten = strInput.ToLower();
//Console.WriteLine("debug // string lower " + strFlatten);
TestPalindrome(ref strFlatten);
//end of program
}
}
}