Im trying to make an annogram. first you input a word, and then it mixes it up and then couts the scrambled version of the word. My problem right now is that when you input a word like "Cat", it will mix up and look like "aCt" or something with the "C" and "at". If you type in "cat" it says you are wrong, because you have to capitalize c. I'm trying to get it to automatically convert any input that is capitalized into lowercase. Here's my code sofar, and I have NO idea how to create lowercase

//---------------------------------------------------------------------------
#include <iostream.h>


#include <algorithm>
#include <iostream>
#include <string>
#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------
#pragma argsused
string scrambbledword;
string originalword;

void shufflefunction(){
        cout << "Please enter a word to be shuffled "<<endl;
        cin >> originalword;

        srand (time (NULL));
        scrambbledword=originalword;
        random_shuffle (scrambbledword.begin(), scrambbledword.end());

        cout << scrambbledword <<endl;
        cout << "Guess the original word" <<endl;
        }

int main(int argc, char* argv[])
{

        string guess;
        int count = 3;

        shufflefunction();

        while (count!=0){
                cin >> guess;

                if ( guess==originalword){
                    cout<<"correct" <<endl;
                         shufflefunction();

                }else if(guess!=originalword){
                    count --;
                    cout << "Incorrect" << endl;
                }
        }



        getch();
        return 0;
}
//---------------------------------------------------------------------------

any help would be appreciated

Recommended Answers

All 4 Replies

Why not use std::ctype::tolower function?

run each letter through this function and it will convert it to lower.

The above is right, though you'll have to change the string to a character array to do that. Here's a really crappy example to show you what I would do.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{     int x = 0;
      string str = "Hello";
      char word[str.length()];

          // Treats str2 like an input stream
      stringstream str2(str);

          // Individual characters placed in word[]
      while (str2 >> word[x])
            { x++; }

          // Converts to lower case
      for (int i = 0; i < str.length(); i++)
          { word[i] = tolower(word[i]); }

          // Shows what word is holding
      for (int j = 0; j < str.length(); j++)
          { cout << word[j] << endl; }

      system("PAUSE");
      return 0;
}

...though you'll have to change the string to a character array to do that

Nope. You can use operator[] to access chars in std::string directly.

Nope. You can use operator[] to access chars in std::string directly.

Yeah. I forgot that.

I've had issues doing that sometimes, so I'm just gotten used to changing char array and then back.

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.