Hangman (Help!) menu

User Tag List

Results 1 to 3 of 3
  1. #1
    Nikentic's Avatar Elite User
    Reputation
    453
    Join Date
    Oct 2007
    Posts
    1,556
    Thanks G/R
    10/4
    Trade Feedback
    6 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hangman (Help!)

    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main(int nNumberofArgs, char* pszArgs[])
    {
    cout <<"Let's play Hangman!\n";
    int wrong;
    int letters;
    wrong = 1;
    
    
    cin >> letters;
    
    if(letters == 'b' || 'i' || 'r' || 'd')
    {
               cout<<"Correct!";
               }
    else
    {
        cout <<"Wrong!";
        wrong++;
    }
    if(wrong <=5)
    {
             cout<<"You Lost!";
             }
    if(letters == 'bird')
    {
               cout<<"You win!";
               }
    system("pause");
    return 0;
    
    
    }
    Int can't be used for letters. What else could i use?

    Hangman (Help!)
  2. #2
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Der are 3 major things that are wrong.

    1. (this is not wrong, but not really good readable) Formatting: Dont use "using namespace std;". As soon as you use the header algorithm you get in trouble cause there are functions as count or sort which pretty soon may interfere with your functions. so keep using namespace where it should be: in the hell! Use always std::cout, std::cin, ... . Use more and consequent spacing: std::cout << "..." and not std::cout<<"...". Its just more readable. Also make correct tabulators.

    2. Check the datatypes. "int wrong; ... wrong = 1;". First you could use char wrong cause it will not have to hold more then 127. That saves you 3 bytes. Second write it as "int wrong = 1;". Saves you code. "int letters". You dont want to read an 4 byte Integer from the input, you want to read a character and because std:stream& operator<< decides from the type how it reads from the inputqueue its important that you define letters as char.

    3. The if-statement cannot be done this way, you need to write:
    if(letters == 'b' || letters == 'i' || letters == 'r' || letters == 'd')

    Otherways the compiler treats it as:
    if(letters == 'b' || 'i' != 0 || 'r' != 0 || 'd' != 0) which is obviously always true because the character i is not 0.

  3. #3
    dwarfhitman's Avatar Member
    Reputation
    13
    Join Date
    Aug 2007
    Posts
    13
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem is you are using letters a bit haphazardly. You first try to use it for character comparison (letters == b|| i|| r||d) then attempt to do a string comparison of some sort.

    Some things you will need to do:
    Change letters to char but you must also realize that if letters is a character variable then you will not be able to do a comparison like you've attempted in the end "letters == 'bird'. This is a string comparison (should be double quotes) of some sort.

Similar Threads

  1. Help WoW Fish-Bot
    By Eliteplague in forum World of Warcraft General
    Replies: 2
    Last Post: 12-10-2024, 05:46 PM
  2. HELP: Gold Scam Exploit
    By GoldDragon in forum World of Warcraft General
    Replies: 11
    Last Post: 01-23-2007, 07:26 PM
  3. Banner Ad Redesign help
    By Matt in forum Community Chat
    Replies: 57
    Last Post: 07-08-2006, 08:40 PM
  4. Hit points and talent points? Please help
    By hankusdankus in forum World of Warcraft General
    Replies: 6
    Last Post: 05-04-2006, 02:00 PM
  5. bot help
    By xwhitedeathx in forum World of Warcraft General
    Replies: 3
    Last Post: 05-01-2006, 03:50 AM
All times are GMT -5. The time now is 11:29 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search