![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
multiple values for one char
i am just messing around with C++ its my first time doing stuff on my own... i am just writing a Q&A quiz... now i ask a question that has multiple answers too.. like for instance if i asked a question "Who was prime minister of england during WWII?" now the answer is Winston Churchill... but say you put in Churchill that is still right... how do you declare multiple values to one decloration??
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
Re: multiple values for one char
I am right in saying your asking for user input and then checking if it matches x.
You would set an array up, then loop through the array checking to see if the input form the user is equal to any of them. Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
Re: multiple values for one char
C++ Syntax (Toggle Plain Text)
is that right? what would come next? or is there a shorter way of doing this? |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Re: multiple values for one char
not quite, along the right lines though.
I myself would do something like this C++ Syntax (Toggle Plain Text)
I understand there may be a few new concepts in there but strings are good to look into for something like this. getline(), may also be new to you. Don't worry have a look at a reference and you should be fine with it. Once you have got the user's input you will want to look at checking to see if the input matches either of the 2 entries in your array. C++ Syntax (Toggle Plain Text)
I hope none of that confuses you too much. one final thing to consider is what happens if i type in "winston churchill" or "Winston cHurchill", are these wrong? i'm happy to explain anything your unclear about Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#5 | |
|
hi: for(;;) goto hi;
|
Re: multiple values for one char
Quote:
c++ Syntax (Toggle Plain Text)
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
Re: multiple values for one char
i just read up on the string and i get that now but the only thing that i dont get is
c++ Syntax (Toggle Plain Text)
Thanks for helping!! |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
Re: multiple values for one char
peaceofpi posted a solution using just an if() statement that you could use. However the for statement is a simple concept and VERY helpful.
to begin with we state we want a for loop, for(). Then we set a variable up used for counting, int i = 0; note i is normally used just by default. then we specify the condition that must be met, i < 2; (i must be less than 2) if the condition is met then we continue to loop, and finally i++, is how we modify i. Each time the loop iterates through i++ is called. Explained here. Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
Re: multiple values for one char
Thanks for the help! and explaining it to me
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
Re: multiple values for one char
Thats what we are here for
![]() Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
Re: multiple values for one char
Freaky Chris you said something about the case sensitive is there something to solve that problem?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |