Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2008, 5:45 PM   #11
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 152
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
Old May 1st, 2008, 3:21 PM   #12
ChevyCowboy15
Newbie
 
ChevyCowboy15's Avatar
 
Join Date: Nov 2007
Location: Central USA
Posts: 12
Rep Power: 0 ChevyCowboy15 is on a distinguished road
Re: multiple values for one char

I have been messing around some more with the for statement i have a question that has 5 possible answers and do this statement
c++ Syntax (Toggle Plain Text)
  1. cout << "question?\n";
  2. getline(cin,answer1);
  3. for (int i=0; i < 5 ; i++){
  4. if (correct[i]==answer1)
  5. cout << "do something!!\n\n";};
  6. else{
  7. cout << "do something!!\n\n";
  8. break;};

then i compile it with g++ and it brings up with error
k.cpp: In function ‘int main()’:
k.cpp:19: error: expected primary-expression before ‘else’
k.cpp:19: error: expected `;' before ‘else’

i cant figure out where to put or take away the ; ??
ChevyCowboy15 is offline   Reply With Quote
Old May 1st, 2008, 3:30 PM   #13
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 152
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: multiple values for one char

C++ Syntax (Toggle Plain Text)
  1. cout << "question?\n";
  2. getline(cin,answer1);
  3. for (int i=0; i < 5 ; i++){
  4. if (correct[i]==answer1)
  5. cout << "do something!!\n\n";
  6. else{
  7. cout << "do something!!\n\n";
  8. }
  9. }

it was just down to bracket placement, i think this will work im sort of busy at the same time so if theres a mistake just let me know. you had placed the else statement outside of the for loop.

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 1st, 2008, 3:33 PM   #14
ChevyCowboy15
Newbie
 
ChevyCowboy15's Avatar
 
Join Date: Nov 2007
Location: Central USA
Posts: 12
Rep Power: 0 ChevyCowboy15 is on a distinguished road
Re: multiple values for one char

That worked thanks.. i thought i tried that but i guess i didnt. thanks again for the help
ChevyCowboy15 is offline   Reply With Quote
Old May 1st, 2008, 3:36 PM   #15
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 152
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: multiple values for one char

your welcome.

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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
Convert char[14] to char * myName C++ 1 Mar 5th, 2006 8:08 PM
Setting value to char pointer element.... tempest C 11 Oct 5th, 2005 3:22 PM
Char assignment using Octal values aznluvsmc C 11 Aug 18th, 2005 5:31 AM
Pointers to return multiple values Clotters C++ 8 Jul 20th, 2005 9:54 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC