Can anybody show me how to implement my string for Easy, Medium, and Hard that contain words. By creating a random number and using that random number to retrieve word from the string and implementing hangman with that word. It will be greatly appreciated.
/*
Title: hangman.cpp
Name: Zain Saeed
Date Created: 2/12/2011
Description:
Usage:
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//Setting up the variable where the data from the file will go to.
string FirstName, Easy, Medium, Hard;
//Setting up the varibale where the user's input will take effect in the switch.
char UserOption;
char Diff;
//Opening the file to retrieve data.
ifstream EasyFile ("easy.txt");
//Making sure if the file is open successfully.
if (EasyFile.is_open())
{
//Going through my file from the begining to the end.
while (!EasyFile.eof())
{
getline (EasyFile, Easy);
cout<<Easy[0]<<endl;
//cout<<Easy<<endl;
}
EasyFile.close();
EasyFile.clear();
}
//Opening the file to retrieve data.
ifstream MediumFile ("medium.txt");
//Making sure if the file is open successfully.
if (MediumFile.is_open())
{
//Going through my file from the begining to the end.
while (!MediumFile.eof())
{
getline (MediumFile, Medium);
//cout<<Medium<<endl;
}
MediumFile.close();
MediumFile.clear();
}
//Opening the file to retrieve data.
ifstream HardFile ("hard.txt");
//Making sure if the file is open successfully.
if (HardFile.is_open())
{
//Going through my file from the begining to the end.
while (!HardFile.eof())
{
getline (HardFile, Hard);
//cout<<Hard<<endl;
}
}
HardFile.close();
HardFile.clear();
//Asking the user to enter thier name.
cout<<"Please enter your first name."<<endl;
//Storing the user's input into the variable FullName.
cin>>FirstName;
//Introducing the hangman game with the user's name in the intro.
int flag =1;
//c is the variable where my user input will be stored.
char c;
//The loop where everything belowe will be repated. Flag is were the value will be input.
//1= true which mean repeat and 0=flase which mean exit.
while (flag)
{
cout<<"Welcome to Hunter Hangman!\n"<<FirstName<<", Have Fun!\n"<<endl;
//Asking the user for the input.
cout<<"Main Menu: Please Type your choice."<<endl;
cout<<"Type 1 to play game."<<endl;
cout<<"Type 2 to exit game."<<endl;
cin>>UserOption;
//Starting my swicth.
switch (UserOption)
{
case '1':
cout<<"Please choose difficulty of the game."<<endl;
cout<<"Press 1 for Easy."<<endl;
cout<<"Press 2 for Medium."<<endl;
cout<<"Press 3 for Hard."<<endl;
cin>>Diff;
switch (Diff)
{
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
}
break;
case '2':
cout<<"Thank you for playing the game."<<endl;
break;
}
//Asking the user if he or she will like another option.
cout<<"Whould you like to choose another option? (Y or N)"<<endl;
//storing the users input into the variable c.
cin>>c;
// if c is N then the flag is 0 which means exit the program.
if ((c == 'N') || (c == 'n')) flag=0;
}
return 0;
}