Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • Try not to use using namespace std Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input into an std::string:

     std::getline(std::cin, guess);
    
  • If you want to avoid case-sensitivity issues, I'd recommend having both guess and the word in the same case (lowercase or uppercase).

    You can use std::transform() on guess to make it lowercase or uppercase, and have the word provided in the same case:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input into an std::string:

     std::getline(std::cin, guess);
    
  • If you want to avoid case-sensitivity issues, I'd recommend having both guess and the word in the same case (lowercase or uppercase).

    You can use std::transform() on guess to make it lowercase or uppercase, and have the word provided in the same case:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input into an std::string:

     std::getline(std::cin, guess);
    
  • If you want to avoid case-sensitivity issues, I'd recommend having both guess and the word in the same case (lowercase or uppercase).

    You can use std::transform() on guess to make it lowercase or uppercase, and have the word provided in the same case:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

added 71 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input into an (may also help with clarity)std::string:

     std::getline(std::cin, guess);
    
  • Does the guess haveIf you want to avoid case-sensitivity issues, I'd recommend having both exactly matchguess and the given word, including cases in the same case (uppercase/lowercase or uppercase)? If not, then you.

    You can do something like this withuse std::transform() on guess to make it lowercase or uppercase, and have the word provided in the same case:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.ignore();
     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input (may also help with clarity):

     std::getline(std::cin, guess);
    
  • Does the guess have to exactly match the given word, including cases (uppercase/lowercase)? If not, then you can do something like this with std::transform():

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.ignore();
     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input into an std::string:

     std::getline(std::cin, guess);
    
  • If you want to avoid case-sensitivity issues, I'd recommend having both guess and the word in the same case (lowercase or uppercase).

    You can use std::transform() on guess to make it lowercase or uppercase, and have the word provided in the same case:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

edited body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() when inputting into anover std::stringoperator>> for all user input (may also help with clarity):

     std::getline(std::cin, guess);
    
  • Does the guess have to exactly match the given word, including cases (uppercase/lowercase)? If not, then you can do something like this with std::transform():

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.ignore();
     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline when inputting into an std::string:

     getline(std::cin, guess);
    
  • Does the guess have to exactly match the given word, including cases (uppercase/lowercase)? If not, then you can do something like this with std::transform:

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.ignore();
     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

  • Try not to use using namespace std.

  • Be sure to include <string> since you're using std::string.

  • Prefer std::getline() over operator>> for all user input (may also help with clarity):

     std::getline(std::cin, guess);
    
  • Does the guess have to exactly match the given word, including cases (uppercase/lowercase)? If not, then you can do something like this with std::transform():

     // get the input
     // transform the guess string to all lowercase
     std::transform(guess.begin(), guess.end(), guess.begin(), ::tolower);
     if (guess == "dog")
     {
     // ...
     }
    
  • The "pause" at the end is okay, but here's another one:

     std::cin.ignore();
     std::cin.get();
    

    This one doesn't involve an extra variable, although it doesn't really matter. The program still "waits" for user input before exiting.

added 214 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /