I am writing a simple (extremely simple) hangman program. Basically the user inputs a word, then they have double the number of letters in the word for guesses (for instance if the word has 7 letters they get 14 guesses). Please don't ask why I want the user to input the word, because it is a homework assignment and that is what the instructor is wanting us to do.
I am having a problem getting the strlen() to write the value to another variable so that I can double it to get the # of guesses and also get one "_" per letter.
// A simple little hangman type game
//
//included libraries
#include <iostream>
#include <stdlib>
#include <conio>
#include <stdio>
#include <fstream>
#include <string>
using namespace std;
// begin program
void main()
{
char getWord[256]; // variable for the inital word
int numLetters; //variable for the number of letters in the word
cout << "Welcome to the hangman program"<<endl;
cout <<"\n Please enter a word" << endl;
cin >>getWord;
strlen(getWord);
printf ("The word entered has %u letters.\n",strlen(getWord));
strlen(getWord)=numLetters;
while(numLetters > 0)
{
cout << "_";
numLetters--;
}
}
edit: I forgot to mention I am using Borland compiler 5.5 and I am getting the following error:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hangman1.cpp:
Error E2277 hangman1.cpp 23: Lvalue required in function main()
*** 1 errors in Compile ***