1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
void randomize(char []);
void Guess(char [], int&,int&);
void main()
{
clrscr();
char word[7]={'\0'};
long int x;
int b,score=0,ctr2=0;
time_t t;
srand((unsigned)time(&t));
ifstream inFile;
b:
inFile.open("words.txt");
if(inFile.fail())
{
cout<<"The file was not opened succesfully\n";
exit(1);
}
inFile.seekg(0L,ios::beg);
x=rand()%1000;
inFile.seekg(x);
inFile>>word;
if(strlen(word)<6)
{
inFile.close();
goto b;
}
cout<<word<<"\n\n\n";
inFile.close();
randomize(word);
Guess(word,score,ctr2);
cout<<"\n\n\t\tYou got a "<<score;
getch();
}
void randomize(char y[7])
{
char A[7]={'\0'};
int i=0,x,k,j,z;
int n[7]={'\0'};
x=strlen(y);
time_t t;
srand((unsigned)time(&t));
cout<<"\n\n\n\t\t\t\t";
while(i<x)
{
a:
j=rand()%x;
z=0;
for(k=0,z=0;k<i;k++)
if(n[k]==j)
z++;
if(z!=0)
goto a;
else
{
n[i]=j;
A[i]=y[j];
cout<<A[i]<<" ";
i++;
}
}
return;
}
void Guess(char word[7],int &score,int &ctr2)
{
int ctr;
a:
ctr=score;
char guess[7]={'\0'};
char quit[4]={'e','x','i','t'};
cout<<"\n What is your guess? "<<ctr2;
cin>>guess;
if(strcmpi(guess,quit)==0);
exit(1);
ifstream inFile;
inFile.open("words.txt");
inFile.seekg(0l,ios::beg);
while(!inFile.eof())
{
inFile>>word;
if(strcmpi(word,guess)==0)
{
score+=strlen(guess)*10;
cout<<"\t"<<strlen(guess)*10;
//Delete(word);
break;
}
}
inFile.close();
if(score==ctr)
{
cout<<"\nYou had a wrong guess\n\n Try again!!\n";
goto a;
}
else if(score>ctr&&score<100)
{
cout<<"\n\n \t\tYou got it right"<<"\nGuess another word";
goto a;
}
else
{
cout<<"\m \n\t\tCONGRATULATIONS\n\n You got all right ";
return;
}
}
| |