Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Noun Issue..

  • 22-10-2011 10:44PM
    #1
    Closed Accounts Posts: 2,663 ✭✭✭


    cant figure out how to get this to work.

    every thing seems find but i cant get if some one enter some thing other then y s ch sh

    add a 's' to the end of it.
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    
    using namespace std;
    
    void findPlural(char *  input, char* &plural);
    
    void findPlural(char *  input, char* &plural)
    
    
    {
        int lenght;
        
        
        lenght = strlen(input);
        
    
        if (input[lenght -1] == 'y') 
        {
            strcpy(plural,input);
            input[lenght -1] = 'i';
            strcat(plural, "es");
            
        } 
        
       else if (input[lenght -1] == 's'|| 'ch' || 'sh')
        {
           strcpy(plural,input);
           input[lenght -1] = 'e';
            strcat(plural, "s");
        }
        else if (input[lenght -1] != 's'||'ch'||'sh'||'y')
        {
            strcpy(plural,input);
           input[lenght -1] = 's';
            strcpy(plural,input);
        }
        
    }
    int main ()
    {
        char noun[30];
        
        char * pural;
        
        
        pural = new char[30];
        
        cout << "Enter a noun" ; 
        cin >> noun;
        
       findPlural(noun, pural);
        
        cout << " The Plural of " << noun << " is " << pural << endl; 
        
        return 0;
    }
    

    its doing my head in.... also for some reason the Noun should read out what i type in and the pural should have Either s,es, ies to to end of the String/Char..


Comments

  • Registered Users, Registered Users 2 Posts: 1,235 ✭✭✭Odaise Gaelach


    Can you give us some examples of what you input and what you get back? :)


  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    when i enter dog it should have dogs but it prints out doges


  • Closed Accounts Posts: 10,833 ✭✭✭✭Armin_Tamzarian


    I'm guessing that English isn't your first language?


    Try changing this

    else if (input[lenght -1] == 's'|| 'ch' || 'sh')



    to this

    else if (input[lenght -1] == 's' || (input[length-2] == 'c' && input[length-1] == 'h'))
    {
    strcpy(plural,input);
    strcat(plural, "es");
    }


  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    I'm guessing that English isn't your first language?
    :confused::confused::confused::confused::confused:

    Either way thanks that done the trick for it!


Advertisement