468,484 Members | 2,096 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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 889

Post your reply

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

Similar topics

reply views Thread by fartsniff | last post: by
6 posts views Thread by Ricky Romaya | last post: by
1 post views Thread by siliconmike | last post: by
1 post views Thread by Evaluating Fuzzy SW | last post: by
3 posts views Thread by arthur benedetti white | last post: by
32 posts views Thread by vonclausowitz | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.