Converting words to numbers ( 1 - 9)

  • Thread starter Thread starter YooOwnIt
  • Start date Start date
Y

YooOwnIt

Guest
Hi,

so I'm trying to convert words to numbers.

I'm having a tough time on how to convert words that have caps (ex one, One, OnE) to 1.

The code so far is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingAssignment4
{
/// <summary>
/// Converts words to digits
/// </summary>
public class Digitizer
{
#region Fields

// declare your Dictionary field and create the Dictionary object for it here
Dictionary<string, int> digitizer = new Dictionary<string, int>();
#endregion

#region Constructor

/// <summary>
/// Constructor
/// </summary>
public Digitizer()
{
// populate your dictionary field here
string str0 = "zero";
string lowerstr0 = str0.ToLower();
digitizer.Add(lowerstr0, 0);



}

#endregion

#region Public methods

/// <summary>
/// Converts the given word to the corresponding digit.
/// If the word isn't a valid digit name, returns -1
/// </summary>
/// <param name="word">word to convert</param>
/// <returns>corresponding digit or -1</returns>
public int ConvertWordToDigit(string word)
{
// delete the code below and add your code
return -1;
}

#endregion
}
}

I've added "return -1;" cause I didn't want to deal with the error CS0161 when testing this. As of now any input returns -1.

Continue reading...
 
Back
Top