ok, I have completely changed the program. I now have three components that work seperately, but not when I attempt to mesh them.
Here is the code individually. Keep in mind that each seperate function is in fact written as a seperate program and when I mesh them I do change variables a bit so that there is no multiple declarations and such. The error I get is
Invalid indirection in function main().
Can someone please help direct me in the proper way to mesh these three pieces together...I was thinking creating 2 parts as header files or some such method.
I am also thinking I am not needing all three parts. Basically I am trying to create the hangman program that uses a users input (the instructor) who will then "guess" the input word, with a mix of capital and non-capital letters and have the program return the word as it is entered (that is if it is Antique it would come out as Antique, AnTiQuE would come out as AnTiQuE and so on) but as long as the letters are there in the correct order it would come out as correct. Also the number of guesses is decremented by 1 each guess. If guesses run out...you are hung. I cannot seem to mesh the parts to come out with a whole though.
This is the attempt at meshing the code:
which causes the aforementioned error
#include <iostream>
#include <string>
using namespace std;
int main()
{
char getWord[50];
char goodGuesses[256] = {'\0'};
char badGuesses[256] = {'\0'};
bool badGuess = true;
char guess;
int guessCount;
int guessCountLimit;
bool sameWord = true;
int t;
int r;
int s;
cout << "Please enter a word" << endl;
cin >> getWord;
//find length of target
int i = 0;
while(getWord[i] != '\0') //stop at null terminator
i++;
guessCountLimit = i*2;
cout << "Guess a letter: ";
cin >> guess;
guessCount = 0;
i = 0;
int j = 0;
int k = 0;
while(guessCount <= guessCountLimit)
{
while(getWord[i] != '\0')
{
if(getWord[i] == guess)
{
goodGuesses[j] = guess;
badGuess = false;
j++; //advance position in goodGuesses
}
i++;
}
if(badGuess)
{
badGuesses[k] = guess;
k++; //advance position in badGuesses
}
i = 0; //reset to go through target again
badGuess = true;
cout << "Good guesses: " << goodGuesses << endl;
cout << "Bad guesses: " << badGuesses << endl;
guessCount++;
//get next guess
cout << "Guess a letter: ";
cin >> guess;
}
//Load up r
i= 0;
while(t[i])
{
r[i] = '-';
i++;
}
//end r with null terminator
r[i] = '\0';
cout << t << " " << r << endl;
cout << "Guess: ";
cin >> guess;
i = 0;
while(guessCount !=guessCountLimit)
{
while(t[i])
{
//cout << guess << " = " << t[i] << endl;
if(guess == t[i])
r[i] = guess;
i++;
}
i = 0;
while(sameWord && t[i])
{
cout << int(t[i]) << " = " << int(r[i]) << endl;
if(t[i] != r[i])
sameWord = false;
i++;
}
i = 0;
if(sameWord)
break;
sameWord = true;
cout << r << endl;
cout << "Guess: ";
cin >> guess;
}
}
Here are the 3 parts
part 1
#include <iostream>
#include <string>
using namespace std;
int main()
{
char getWord[50];
char goodGuesses[256] = {'\0'};
char badGuesses[256] = {'\0'};
bool badGuess = true;
char guess;
int guessCount;
int guessCountLimit;
cout << "Please enter a word" << endl;
cin >> getWord;
//find length of target
int i = 0;
while(getWord[i] != '\0') //stop at null terminator
i++;
guessCountLimit = i;
cout << "Guess a letter: ";
cin >> guess;
guessCount = 0;
i = 0;
int j = 0;
int k = 0;
while(guessCount <= guessCountLimit)
{
while(getWord[i] != '\0')
{
if(getWord[i] == guess)
{
goodGuesses[j] = guess;
badGuess = false;
j++; //advance position in goodGuesses
}
i++;
}
if(badGuess)
{
badGuesses[k] = guess;
k++; //advance position in badGuesses
}
i = 0; //reset to go through target again
badGuess = true;
cout << "Good guesses: " << goodGuesses << endl;
cout << "Bad guesses: " << badGuesses << endl;
guessCount++;
//get next guess
cout << "Guess a letter: ";
cin >> guess;
}
}
Part 2 (compares the input "strings")
//end r with null terminator
r[i] = '\0';
cout << t << " " << r << endl;
cout << "Guess: ";
cin >> guess;
i = 0;
while(1)
{
while(t[i])
{
//cout << guess << " = " << t[i] << endl;
if(guess == t[i])
r[i] = guess;
i++;
}
i = 0;
while(sameWord && t[i])
{
cout << int(t[i]) << " = " << int(r[i]) << endl;
if(t[i] != r[i])
sameWord = false;
i++;
}
i = 0;
if(sameWord)
break;
sameWord = true;
cout << r << endl;
cout << "Guess: ";
cin >> guess;
}
Part 3 (makes it case insensitive)
#include <iostream>
using namespace std;
int main()
{
char a[] = "Hello";
char b[256];
//load up b with capped a
int i = 0;
for( ; a[i]; i++)
{
b[i] = a[i];
//cap non-capped
if(b[i] > 96 && b[i] < 123)
b[i] = b[i] - 32;
}
b[i] = '\0';
cout << a << " " << b << endl;
return 0;
}