Hi, so I'm trying to turn a textual amount (e.g., "nineteen thousand nine hundred fifty two") into a numerical amount (e.g., "19952") using a linear search. Here is what I have so far, but I know they're is much more to do.
CODE
#include<iostream>
using namespace std;
int LinearSearch(char [], int, int);
const int SIZE = 11;
int main()
{
char phrase[100];
char thou[SIZE][6] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
char hun[SIZE][6] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
char ten[SIZE][6] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
char one[SIZE][6] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
cout << "Enter textual check amount: ";
cin >> phrase;
int nthou = LinearSearch(thou,SIZE,phrase);
int nhun = LinearSearch(hun,SIZE,phrase);
int nten = LinearSearch(ten,SIZE,phrase);
int nones = LinearSearch(one,SIZE,phrase);
int value = (nthou*1000) + (nhun*100) + (nten*10) + (nones*1);
cout << value << endl;
return 0;
}
int LinearSearch(char list[],int numElems,int search_item)
{
int index = 0;
bool found = false;
int position = 0;
while (index < numElems && !found)
{
if (list[index] == search_item)
{
found = true;
position = index;
}
index++;
}
return position;
}
Anything will help!! Thank you!!
*Mod Edit: added code tags: