hi guys , im designing a c++ code for an assignment and im badly stuck.i have to create a programme word checker to change plurals to nouns. i have it completed but have to store it as statistics. so when the user selects the VIEW button at the end of any game, he or she can view the nouns and plurals they have entered up to then.
please help me out. here is my code.:::

#include<iostream>//include in/out stream library
#include <string> //include standard string library





using namespace std;//using the naming convention std
int main ()
{


          int replay;
     char option [2];
     cout<<"welcome to spellcheck,below are your main options, please select one, thank you"<<endl;

 cout<<"Menu: \n\n";
 cout<<"1. Start\n\n";
 cout<<"2. View\n\n";
 cout<<"3. Close\n\n";


   cin>> option;
     if(option[0] == '1')
   {
     cin.get();
    system("CLS");
                string singWord, pluralWord;
    int n;
    char lastChar, secLastChar;
 start:
    cout<<"Please enter a word: "<<endl;

    while (true)
    {
        cin>>singWord;
        n=singWord.length();
        lastChar=singWord[n-1];
        secLastChar=singWord[n-2];

        if (singWord == "deer"){
    cout<<"The word is a special word. \n";
    cout<<"The plural of "<<singWord <<" is "<<singWord<<endl;

}
else if (singWord =="moose"){

cout<<"The word is a special word";
cout<<"The plural of "<< singWord <<" is "<<singWord<<endl;

}


else if (singWord =="sheep"){
      cout<<"The word is a special word";
cout<<"The plural of "<< singWord <<" is "<<singWord<<endl;
}
        else if (lastChar=='y'){
            pluralWord=singWord.substr(0,n-1)+"ies";
            cout<<"The plural word is: "<<pluralWord<<endl;
        }
        else if (lastChar=='o'||lastChar=='s'||lastChar=='x'){
            pluralWord=singWord+"es";
            cout<<"The plural word is: "<<pluralWord<<endl;
        }
        else if (lastChar=='h'&& lastChar=='c'){
            pluralWord=singWord+"es";
            cout<<"The plural word is: "<<pluralWord<<endl;
        }
        else if (lastChar== 'f'){
            pluralWord=singWord.substr(0,n-1)+"ves";
            cout<<"The plural word is: "<<pluralWord<<endl;
        }
        else if (lastChar=='e'&&secLastChar=='f'){
            pluralWord=singWord.substr(0,n-2)+"ves";
            cout<<"The plural word is: "<<pluralWord<<endl;
        }
        else{
            pluralWord=singWord+"s";
            cout<<"The plural word is: "<<pluralWord<<endl;
      }
      cout<<"do you want to play again? press 1 for yes and 2 for no"<<endl;
      cin>>replay;
      cout<<"you choose "<<replay<<" .thank you"<<endl;

   while (replay <=0)//declare a while loop for negatives
      {//start of line verification
      cout<<"YOU HAVE ENTERED THE INVALID NUMBER OF "<<replay<<" . PLEASE TRY AGAIN!! "<<endl;//show user their invalid entry
      cout<< "PRESS 1 TO RESTART THE GAME AND 2 TO FINISH THE GAME, THANK YOU"<<endl;//give the user the options again
      cin>>replay;//user input
      }//end of line verification

       if (replay >=3 )// if the case where entry greater than 3
 {//start of line verification
      cout<<"YOU HAVE ENTERED THE INVALID NUMBER OF "<<replay<<" . PLEASE TRY AGAIN!! "<<endl;//show user their invalid entry
      cout<< "PRESS 1 TO RESTART THE GAME AND 2 TO FINISH THE GAME, THANK YOU"<<endl;//give the user the options again
      cin>>replay;//please enter input
      }//end of line verification

if (replay ==2) return 0;//if input is 2,then quit the game

 if (replay ==1) goto start;//if input is 1 then restart the game and send programme back to start  



    }
    cin>>option;          
     }else if (option[0] == '2'){
     system("CLS");
     cout<<"Game Stats!\n";

     }else if (option[0] == '3'){
        return 0;   
            }





    system("pause"); //pause the system so the judges can see the result before ending
        return 0;
    }//end of line verification

Recommended Answers

All 2 Replies

Here's one way to do it using vectors:

    #include <iostream>
    #include <string>
    #include <vector>
    using namespace  std;
    vector<string> singles;
    vector<string> plurals;
    void Pause()
    {
        cin.ignore();
        cin.get();
    }
    void CLS()
    {
        cout << string( 100, '\n' );
    }
    void Play()
    {
        string singWord, pluralWord;
        cout<<"Please enter a word: "<<endl;
        cin>>singWord;
        int n=singWord.length();
        char lastChar=singWord[n-1];
        char secLastChar=singWord[n-2];
        if (singWord == "deer" || singWord =="moose" || singWord =="sheep")
        {
            cout<<"The word is a special word. \n";
            pluralWord = singWord;
        }
        else if (lastChar=='y')
        {
            pluralWord=singWord.substr(0,n-1)+"ies";
        }
        else if (lastChar=='o'||lastChar=='s'||lastChar=='x' || (lastChar=='h'&& secLastChar=='c'))
        {
            pluralWord=singWord+"es";
        }
        else if (lastChar== 'f')
        {
            pluralWord=singWord.substr(0,n-1)+"ves";
        }
        else if (lastChar=='e'&&secLastChar=='f')
        {
            pluralWord=singWord.substr(0,n-2)+"ves";
        }
        else
        {
            pluralWord=singWord+"s";
        }
        cout<<"The plural word is: "<<pluralWord<<endl;
        singles.push_back(singWord);
        plurals.push_back(pluralWord);
        Pause();
    }
    void Stats()
    {
        CLS();
        cout << "Single\tPlural" << endl;
        for(unsigned i=0; i<singles.size(); i++)
            cout << singles[i] << "\t" << plurals[i] << endl;
        Pause();
    }

void PlayMenu()
{
    char option;
    while(option != '0')
    {
        CLS();
        cout << "Play Menu:\n" ;
        cout << "1. New Word\n";
        cout << "0. Done\n";
        cin >> option;
        switch(option)
        {
        case '1':
            Play();
            break;
        default:
            break;
        }
    }
}

int main()
{

    char option;

    while(option != '0')
    {
        CLS();
        cout<<"welcome to spellcheck,below are your main options, please select one, thank you"<<endl;
        cout<<"Menu: \n\n";
        cout<<"1. Play\n\n";
        cout<<"2. View\n\n";
        cout<<"3. Reset Game\n\n";
        cout<<"0. Close\n\n";
        cin>> option;
        switch ( option )
        {
        case '1':
            PlayMenu();
            break;
        case '2':
            Stats();
            break;
        case '3':
            singles.clear();
            plurals.clear();
            break;
        default:
            break;
        }
    }
    return 0;
}

thank you very much. for some reason the screen crashes when i load that code.appreciated do. i got it solved myself aswell. i wasnt sure how to use vectors but figured it out. very handy. iadded this into it

      //VECTORS
  wordsChecked.push_back(firstWord);
  wordPlurals.push_back(pluralWord);
  count += 1;






      cout<<"do you want to play again? press 1 for yes and 2 for no and 3 to go to main menu"<<endl;
      cin>>replay;
      cout<<"you choose "<<replay<<" .thank you"<<endl;

  if (replay ==1) goto start2;

if (replay ==2) return 0;//if input is 2,then quit the game

 if (replay ==3) goto start;//if input is 3 then restart the game and send programme back to start  
}



     }else if (option[0] == '2'){


    system("CLS");
    cout<<"Game statistics!\n";

    for(int i=0; i < count; i++) 
          {
                cout<<"   "<<counter<<"\t\t "<<wordsChecked[i]<<"\t    -------"<<"\t     "<< wordPlurals[i]<<"\t      "<<endl;
                cout<<endl;
                counter +=1;
          }

    cout<<"Press (ENTER) key to enter main menu!";
    cin.ignore(256,'\n');
    cin.get();
    system("CLS");

    counter = 1;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.