View Single Post
Old Apr 30th, 2008, 5:45 PM   #11
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: multiple values for one char

Indeed there is, im not thinking straight as im falling asleep but anyway you could use something like this.

C++ Syntax (Toggle Plain Text)
  1. #include <cctype>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. string stripcase(string instring){
  7. string buffer = "";
  8. for(int i = 0; i < instring.length(); i++){
  9. buffer += tolower(instring[i]);
  10. }
  11. return buffer;
  12. }
  13.  
  14. int main()
  15. {
  16. string input1 = "winSton Chruchill"; //this would be set via user input of course, just an example
  17.  
  18. string correct1 [2] = {"Winston Churchill", "Chruchill"};
  19.  
  20. for(int i = 0; i < 2; i++)
  21. {
  22. if(stripcase(correct1[i]) == stripcase(input1)){
  23. cout << "Congratulations, you got it!";
  24. }
  25. }
  26.  
  27. return 0;
  28. )

Something like that is what your after, there are probably better ways but i cannot thing straight right now, im gonna shoot off anyway so if you need it explaining then im sure one of the other guys will help. If not i will when im next online.

I recomment reading up on cctype as this will help you understand what is going on, also you should be aware that you are able to treat strings as char arrays, these will help you understand this.

C++ Syntax (Toggle Plain Text)
  1. buffer += tolower(instring[i]);

Cheers,
Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote