473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Soundex in c++

I got most of it working but I cant find a good way for it to end the program at the end of the word and if its less than 4 letters to add 0's at the end. so for i got


Expand|Select|Wrap|Line Numbers
  1. //Generate Soundex Code
  2. #include <iostream>
  3. #include <ctype.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     char first,letter;
  8.     int count=1, leftover;
  9.     cin>>first;
  10.     cout<<first;
  11.     do  {    
  12.         cin>>letter;
  13.         switch (letter)
  14.         {
  15.             case 'b':
  16.             case 'f':
  17.             case 'p':
  18.             case 'v':
  19.             case 'B':
  20.             case 'F':
  21.             case 'P':
  22.             case 'V':
  23.                 cout<<"1";
  24.                 count++;
  25.                 break;
  26.             case 'c':
  27.             case 'g':
  28.             case 'j':
  29.             case 'k':
  30.             case 'q':
  31.             case 's':
  32.             case 'x':
  33.             case 'z':
  34.             case 'C':
  35.             case 'G':
  36.             case 'J':
  37.             case 'K':
  38.             case 'Q':
  39.             case 'S':
  40.             case 'X':
  41.             case 'Z':
  42.                 cout<< "2";
  43.                 count++;
  44.                 break;
  45.             case 'd':
  46.             case 'D':
  47.             case 't':
  48.             case 'T':
  49.                 cout<<"3";
  50.                 count++;
  51.                 break;
  52.             case 'l':
  53.             case 'L':
  54.                 cout<<"4";
  55.                 count++;
  56.                 break;
  57.             case 'm':
  58.             case 'M':
  59.             case 'N':
  60.             case 'n':
  61.                 cout<<"5";
  62.                 count++;
  63.                 break;
  64.             case 'r':
  65.             case 'R':
  66.                 cout<<"6";
  67.                 count++;
  68.                 break;
  69. }
  70.         } while ((iscntrl(letter)) or (count=4));
  71.         for(leftover=count;leftover<4;leftover++);
  72.             {
  73.             cout<<"0";
  74.             }
  75.     cout<<endl;
  76. }
the counter or the leftover isnt working right and like for the name Wilbur is does W4160 and makes it 5 but for Eib it just does E1 and dosnt add any 0's ty in advance
Jan 11 '08 #1
0 1029

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: fartsniff | last post by:
hey all, i am currently using a search engine on my site that compares values stored in the meta tags with what the user types in. any matches return the "title" of the page, a thumbnail and a...
6
by: Ricky Romaya | last post by:
Hi, I'm curious about soundex. All I know that it's a way for making spelling- error-tolerant word matching. What I want to know is whether the soundex algorithm are made exclusively for english...
1
by: siliconmike | last post by:
Hi I'm using SOUNDEX mysql function to find similar sounding names from a table with 2 million distinct names. Unfortunately there is a single soundex code for every 200,000 names! Meaning there...
1
by: Evaluating Fuzzy SW | last post by:
Hi All We are using soundex (and later tried Nysiis) for fuzzy name search software. But we faced a lot of problems the search accuracy was not very good also we saw a lot of misses of...
3
by: arthur benedetti white | last post by:
has anybody already developed a server side soundex function?
3
by: Vinay Jain | last post by:
Hi I want to write soundex query for example: select * from student where name soundex 'vinay'; In psql it gives error at soundex. Regards Vinay -- Vinay Jain Dissertation Project Trainee...
32
by: vonclausowitz | last post by:
Hi All, I have database with names on which I want to use the soundex option. So I have created two seperate fields for the Lastname and Firstname in which I save the Soundex version of a new...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.