I am getting an Error stating canot convert string to Char type

code is as follows

/*
Jonathan Thomas 
ITSE 2421 intro to object C++
 begin sudo code:
      function   takes in string variable called "verb"
      function uses string  function verb.length to determine length of string assigns value to size
      compares last value in the string whether it is a consanant or an E 
      function convert string to array
      converts back to string
      if last letter  is 'e' the letter will be dropped and replaced with 'ing' using verb.replace(size,3,ing)
      

*/

#include<iostream>
#include<string>
using namespace std;
void createParticiple(string);
bool isVowel(char);
int main()
{
    string verb;
   
           cout<<"this prgram conjugates verbs into the past participle"<<endl;
           cout<<"please enter a verb in lower case letters NO CAPITOLS!!!"<<endl;
           getline(cin, verb);
           
           createParticiple(verb);
           
           system("pause");
}//end of line
void createParticiple(string verb)
{ 
     int size= verb.length();
   string s2;
    string LL;
    string NTL;
    char *lastLetter[1];
    char *nextToLast[1];
     
        LL= verb.substr( size-1, 1);
        NTL= verb.substr(size-2,1);
       
       
      lastLetter=&LL[0];
      nextToLast=&NTL[0];
        
        
      
       if (*lastLetter== "e" && isVowel==false )
       {verb.append(size-1, "ing");};
       
       if (isVowel==false && *lastLetter!="e" )
       {verb.append(size-2, nextToLast);
         verb.append(size, "ing") ;}
       
        
               
     
            
}
bool isVowel(char nextToLast)
{ 
     if (nextToLast=='a' || nextToLast=='e' || nextToLast=='i' || nextToLast=='o' || nextToLast=='u')
      { return true;}
      else {return false;}
}

I wouldn't make lastLetter and nextToLast neither pointers nor arrays (there's not much point to having a 1 element array anyway). I would make them both chars and set lastLetter to verb[size-1] and the other to verb[size-2] (using the array notation for the string).

Another problem you are going to run into is you are not calling isVowel properly since you aren't passing it any parameters. You need to send in the nextToLast character.

Just a nitpicky thing but you don't have to use the whole if(statement) return true; bit, just return statement; if it's true it will return true and vice versa.

Edited 6 Years Ago by jonsca: n/a

thanks Jonsca!

I have it compiling but it will not show the entire thread

/*
Jonathan Thomas 
ITSE 2421 intro to object C++
 begin sudo code:
      function   takes in string variable called "verb"
      function uses string  function verb.length to determine length of string assigns value to size
      compares last value in the string whether it is a consanant or an E 
      function convert string to array
      converts back to string
      if last letter  is 'e' the letter will be dropped and replaced with 'ing' using verb.replace(size,3,ing)
      

*/

#include<iostream>
#include<string>
using namespace std;
void createParticiple(string);
bool isVowel(char);
int main()
{
    string verb;
   
           cout<<"this prgram conjugates verbs into the past participle"<<endl;
           cout<<"please enter a verb in lower case letters NO CAPITOLS!!!"<<endl;
           getline(cin, verb);
           
           createParticiple(verb);
           
           system("pause");
}//end of line
void createParticiple(string verb)
{ 
    int size= verb.length();
    string conjugated;
    string s2;
    string LL;
    string NTL;
    char lastLetter;
    char nextToLast;
     
       s2="ing";
       
       
      lastLetter= verb[size-1];
      nextToLast=verb[size-2];
        
      
       if (lastLetter== 'e' && isVowel(nextToLast)==false )
       {conjugated=verb[size]-verb[size-1];
       
       conjugated=verb[size]+s2;};
       
       if (isVowel(nextToLast)==false && lastLetter!='e' )
       {conjugated=verb[size] -verb[size-2]+nextToLast;
       size=verb.length();
       conjugated=conjugated[size]+s2;}
       
        
               
     cout <<"you entered "<<verb<<" \n \n the present participle is "<<conjugated<<endl;
            
}
bool isVowel(char nextToLast)
{ 
     if (nextToLast=='a' || nextToLast=='e' || nextToLast=='i' || nextToLast=='o' || nextToLast=='u')
      { return true;}
      else {return false;}
}

i mean I cannot get it to display the complete string.

the out put should be the word +ing..

or the word -'e' + ing

or the word +nextToLast +ing

when i complile it only shows ing

There's an extra semicolon at the end of line 52, but that's not the main problem.

This line (and all similar ones) is incorrect:

conjugated=verb[size]-verb[size-1];

Firstly, verb goes off the end of the array (elements go from position 0 to size-1). Secondly, I don't think the - operator can be used like the reverse of the + operator with strings. It compiled because you were taking the numerical difference of 2 characters (one, a "junk" value from an adjacent memory address and the other being the last character) which is really just a calculation with 1 byte integers.

Anything that references verb has to be changed (and remember an element of the string is just a single character so you need the whole string).

So you'll need to restructure those sections. Perhaps consider copying the result into a new array or something similar. It's nice to try to do it in place but it's making your life difficult.

Edited 6 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.