Thanks for the welcome. Everybody replied so fast. I appreciate y'alls input already. For what it's worth, here is my code. It works on my windows machine without a problem. It is unfinished btw, just a homework assignment for my c++ class. I can't find any bugs... anymore input would be amazing. You guys have been great so far.
Code:
#include <iostream> //every program has this.
#include <cstdlib> //standard library.
#include <ctime> //for random.
#include <fstream> //for reading and writing to a file.
#include <string>
using namespace std;
int main(){
ifstream infile;
ofstream outfile;
int x;
int word_length;
string word_selection;
string words[100];
char letter_bank[100]; // holds the letters of the selected word.
char play; // for continuation of the game.
cout << "Would you like to play hangman? (Enter y or n): ";
cin >> play;
if(play == 'y' || play == 'Y'){
infile.open("hangman_input.txt");
while(infile){
infile >> x;
for (int i = 0; i < x; i++){
infile >> words[i];
}
}
long seed = time(NULL); // gets current time
srand(seed);
int random_num = rand() % x; // Computer's random selection
cout << random_num << endl;
cout << random_num << endl;
word_selection = words[random_num]; // This is the word we will play hangman with.
word_length = word_selection.length();
cout << word_selection << " is " << word_length << " letters long" << endl;
// Below is the end of the YES option...
}
else{
cout << "Good bye." << endl;
}
cout << "This is the value for x: " << x << endl;
return 0;
}
Bookmarks