By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,706 Members | 2,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,706 IT Pros & Developers. It's quick & easy.

C++ Unfinished Program

P: 5
My code is pasted at the bottom

I am writing a program that gives a user four (4 options)
1) Reorder Sentence
2) Sentence Encryption
3) Count Vowels
4) Quit

My problem is that I have completed options 3 (Count Vowels) and 4 (Quit), but i am having some problems with options 1 and 2.
first of all in option 1; case 1 (Reorder Sentence), my program displays to the user to type the sentence The cat mat sat the on--this part of the program works fine. When the user inputs the sentence the program should then display to the user choices of the words to switch which will then reorder the sentence.I am having a problem with this part of the program.
Secondly, my Sentence Encryption program (case 2) is suppose to encrypt the words The Cat. I am not getting a full encryption--I am only getting 20

please can someone hep me with this
Expand|Select|Wrap|Line Numbers
  1.  
  2.     string userString;
  3.     char c = userString[0];
  4.     int count[80]={0} ;
  5.     int counter_a [80]= {0};
  6.     int counter_e [80]= {0};
  7.     int counter_i [80]= {0};
  8.     int counter_o [80]= {0};
  9.     int counter_u [80]= {0};
  10.  
  11.  
  12.  
  13.     int d;
  14.     int getenc_letter;
  15.     string userstring;
  16.     char a;
  17.  
  18.  
  19.     int option;
  20.  
  21.     cout<<"Select Your Sentence Manipulation Option"<<endl;
  22.  
  23.     cout<<"Enter:"<<endl;
  24.  
  25.     cout<<"1)"<<"Reorder Sentence"<<endl;
  26.  
  27.     cout<<"2)"<<"Sentence Encryption"<<endl;
  28.  
  29.     cout<<"3)"<<"Count Vowels"<<endl;
  30.  
  31.     cout<<"4)"<<"Quit"<<endl;
  32.  
  33.     top:
  34.  
  35.     cin>>option;  
  36.  
  37.     switch (option)
  38.     {
  39.            case 1: 
  40.  
  41.                 cout<<"you have selected the Reorder Sentence option"<<endl;
  42.  
  43.                 cout<<"Enter the Sentence:"<<" "<<"The cat mat sat the on"<<endl;
  44.  
  45.                 do{
  46.                     getline (cin,word);
  47.                     sentence[counter] = word;
  48.                     counter++;
  49.                    }while(word!="Q");
  50.  
  51.  
  52.                     temp = sentence[firstPos2];
  53.                     sentence[firstPos2] = sentence[secondPos2];
  54.                     sentence[secondPos2] = sentence[thirdPos2]; 
  55.                     sentence[thirdPos2] = sentence[fourthPos2];
  56.                     sentence[fourthPos2] = sentence[fifthPos2];
  57.                     sentence[fifthPos2] = sentence[sixthPos2];
  58.                     sentence[sixthPos2] = temp;
  59.  
  60.  
  61.  
  62.                     for(int x=0; x<counter-1; x++)   
  63.                      {
  64.  
  65.                         cout<<sentence[x]<<" ";
  66.  
  67.                      }
  68.                        {
  69.  
  70.                            cout<<"The choices are"<<endl;
  71.  
  72.                        }
  73.                        {
  74.                            cout<<"CHOICES"<<setw(9)<<"WORDS"<<endl;
  75.  
  76.                            cout<<setw(7)<<firstPos2<<setw(9)<<sentence[firstPos2]<<endl;
  77.  
  78.                            cout<<setw(7)<<secondPos2<<setw(9)<<sentence[secondPos2]<<endl;
  79.  
  80.                            cout<<setw(7)<<thirdPos2<<setw(9)<<sentence[thirdPos2]<<endl;
  81.  
  82.                            cout<<setw(7)<<fourthPos2<<setw(9)<<sentence[fourthPos2]<<endl;
  83.  
  84.                            cout<<setw(7)<<fifthPos2<<setw(9)<<sentence[fifthPos2]<<endl;
  85.  
  86.                            cout<<setw(7)<<sixthPos2<<setw(9)<<sentence[sixthPos2]<<endl;
  87.  
  88.                            cout<<"Rearrange the sentence by entering the position of the words"<<endl;
  89.  
  90.                            cout<<"Enter first position"<<endl; 
  91.  
  92.                        }
  93.  
  94.                            for(pos=0;pos<6;pos-1)
  95.  
  96.                            do{
  97.  
  98.                                   cin>>pos;
  99.  
  100.                                   if (pos >=0 && pos < 6 )
  101.  
  102.                                   {
  103.  
  104.                                        cout<<sentence[pos];
  105.  
  106.                                        pos++;
  107.  
  108.                                        cout<<"Enter the next position"<<endl;
  109.  
  110.                                   }
  111.                                   else
  112.  
  113.                                   {
  114.  
  115.                                       cout<<"invalid Position Entered"<<"\0"<<" Re-enter The First Position"<<endl;
  116.  
  117.                                   }
  118.  
  119.                              }while (pos >  0);
  120.  
  121.                 break;
  122.  
  123.            case 2: 
  124.                 cout<<"You have selected the Sentence Encryption option"<<endl;
  125.                 cout<<"Enter the sentence: The Cat"<<endl; 
  126.  
  127.                 for (a=0;a<20;a++)
  128.  
  129.                 do{
  130.  
  131.                       cin>>userstring;
  132.  
  133.                       a = userstring[0];
  134.  
  135.                       getenc_letter= (int)(a - 64);
  136.  
  137.                       a++;
  138.  
  139.                       cout<<getenc_letter<<endl;
  140.  
  141.                   }while(a < userstring.length());   
  142.  
  143.                       {
  144.  
  145.                        cout<<userstring[getenc_letter];
  146.  
  147.                       } 
  148.  
  149.                    break;
Nov 18 '08 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Start by splitting those functionalities into separate functions which you call from the switch. The code becomes easier to debug that way.
Nov 18 '08 #2

Post your reply

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