| | |
toupper function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 113
Reputation:
Solved Threads: 4
I've got a pretty simple question. I'm trying to ask the player for to choose a difficulty. I want the case to be to not affect his choice, so I am using the toupper() function. Unfortunately, when I try to return the value of the difficulty, no matter what difficulty I choose, I receive 2009768935. However, when I enter an answer is all caps, avoiding the use of the toupper() function, everything turns out great.
Here is my code.
Here is my code.
C++ Syntax (Toggle Plain Text)
cout << "Choose a difficulty among Easy, Intermediate, and Hard."; string x; int difficulty; cin >> x; for (int i =0; i <=12; i++) { x[i] = x[toupper(i)]; } if (x == "EASY" ) { difficulty = 0; } if (x == "INTERMEDIATE" ) { difficulty = 1; } if (x == "HARD" ) { difficulty = 2; } cout << difficulty;
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
why dont you do something like this
C++ Syntax (Toggle Plain Text)
if (x == "EASY" || "easy" ) { difficulty = 0; } // and so on..
•
•
•
•
Originally Posted by joshmo
> why dont you do something like this
> if (x == "EASY" || "easy" )
if ( ( x == "EASY" ) || ( "easy" != NULL ) ) In essence, it's always true, because the right hand side is always true, and the OR makes the whole thing true.
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
thanx for the correction...didnt see it there.. but actully this was the intetion
C++ Syntax (Toggle Plain Text)
if (x == "EASY" || x=="easy" )
Last edited by joshmo; Jun 7th, 2008 at 6:40 am.
C++ Syntax (Toggle Plain Text)
#include <cctype> // for toupper() #include <algorithm> // for transform() transform(x.begin(), x.end(), x.begin(), toupper);
try this
Last edited by Cybulski; Jun 7th, 2008 at 7:27 am.
![]() |
Similar Threads
- C a function to uppercase a string (C)
- Changing strin into uppercase (C++)
- sentence capitalizer (C++)
- help writing a grep program (C)
Other Threads in the C++ Forum
- Previous Thread: Use a function from a different file (C++)
- Next Thread: Vector and virtual function questions
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






