I'm working on a problem that wants me to get a string input from a user, run it through a method which will check every character to see if it follows the pattern of American currency. It has to be a string that goes into the method. the amount can be any where from 1 dollar to a thousand but must have the format entered as $x.xx, $xx.xx, $xxx.xx, as long as the user enters an amount that is consistent with the above formats then my program should output that its "valid" anything else would be a "invalid format" output. first character must be the '$' and I cannot use regex.
I get the user input and then validate it with .NullOrWhiteSpace. and then send the string value holding the user input down to my created method. from this point I have no idea how to continue. I've tried .ToCharArray, I have also tried making a long and complicated if statement and I have researched for a few hours now but can't find a solid way to write this out.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter amount between $1.00 and $1000.00");
string valueUS = Console.ReadLine();
while (string.IsNullOrWhiteSpace(valueUS))
{
Console.WriteLine("Please enter in an amount");
valueUS = Console.ReadLine();
}
currencyChecker(valueUS);
}
public static string currencyChecker(string currencyString)
{
char[] currencyArray;
currencyArray = currencyString.ToCharArray();
for (int i = 0; i < currencyArray.Length; i++)
{
if (currencyArray[0] == '$')
{
}
}
return currencyString;
the method below should check every character entered by the user and verify that it matches the above described pattern for American currency and output that its "valid" anything else should be reported back as "invalid"