| | |
Need help, having input problems.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 0
Ok, I know I'm probably programing in some kind of archaic way for C++ but my knowledge base is rather limited.
I'm having problems with my input not being identified correctly (or however you would say it, rusty is me)
When You type in like Dex or something it still only applies the strength bonus. Also if you type in random letters it only goes to the "//strength changes" part of the code instead of the "//error statement" part of the code. Can someone help me resolve this issue? Or bring me up to speed with some code that could help me?
I'm having problems with my input not being identified correctly (or however you would say it, rusty is me)
C++ Syntax (Toggle Plain Text)
cin>>StatsChange; if (StatsChange == "Strength" or "strength" or "str" or "STR" or "Str") { //Strength Changes Strength = Strength + 1; abilpts = abilpts -1; goto hpmpstat; } else if (StatsChange == "Dexterity" or "dexterity" or "dex" or "DEX" or "Dex") { //Dexterity Changes Dexterity = Dexterity + 1; abilpts = abilpts -1; goto hpmpstat; } else if (StatsChange == "Constitution" or "constitution" or "con" or "CON" or "Con") { //Constitution Changes Constitution = Constitution +1; abilpts = abilpts - 1; goto hpmpstat; } else if (StatsChange == "Intelligence" or "intelligence" or "int" or "INT" or "Int") { //Intelligence Changes Intelligence = Intelligence + 1; abilpts = abilpts -1; goto hpmpstat; } else if (StatsChange == "Wisdom" or "wisdom" or "wis" or "WIS" or "Wis") { //Wisdom Changes Wisdom = Wisdom + 1; abilpts = abilpts -1; goto hpmpstat; } else if (StatsChange == "Charisma" or "charisma" or "cha" or "CHA" or "Cha") { //Charisma Changes Charisma = Charisma +1; abilpts = abilpts -1; goto hpmpstat; } else { //error statement cout<<"You fail"<<endl; system("PAUSE"); goto CCRT; }
1
#2 Oct 23rd, 2009
C++ Syntax (Toggle Plain Text)
if (StatsChange == "Strength" or "strength" or "str" or "STR" or "Str")
should be:
C++ Syntax (Toggle Plain Text)
if (StatsChange == "Strength" || StatsChange == "strength" || StatsChange== "str" || StatsChange== "STR" ||StatsChange== "Str")
I know, believe me I did the same thing when I first got into boolean logic.. because the way you do it (aside from the incorrect symbology) seems correct at first, and more code efficient. However, please realize that there are specific rules at play here; each expression is handled individually.
If only one variable exists, the boolean test will either return TRUE if not zero, and FALSE if zero. Example:
C++ Syntax (Toggle Plain Text)
if(variable) { //code }
In this instance, if 'variable' contains any value, it will test TRUE and will enter/execute the contents of the if() structure. Conversely, if 'variable' contains a zero, the boolean expression will test FALSE and will simply skip over the entire if() structure.
So like me, you are probably wondering how to avoid these huge multiple lines of logic. Here is one way I can think of:
C++ Syntax (Toggle Plain Text)
string input = {"Strength", "strength", "str", "STR", "Str"}; bool match = FALSE: int i=0; do{ if(StatsChange == input[i]) { match = TRUE; } }while(match == FALSE || i < 5);
Placing boolean tests inside of a loop could potentially eliminate several lines of logical testing.
Last edited by Clinton Portis; Oct 23rd, 2009 at 11:59 pm.
![]() |
Similar Threads
- User Input Problems (C)
- file input problems (with windows?) (Java)
- calculator program (Java)
- Continued Tic Tac Toe help (C)
Other Threads in the C++ Forum
- Previous Thread: Waiting between lines
- Next Thread: Homework help needed for displaying ASCII Characters
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





