i have a text file which i put all the strings into a vector. i have successfully been able to search through the vector, however i want the words typed in only to be counted correct if they are made from the random characters given at the start of the game. you will the what i mean when you play the game... is there a way to do that? thanks!
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include"dos.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "windows.h"
#include<string>
usingnamespace std;
void load_file(){
ifstream file;
file.open("");
file.open ("c:\\TEXT TWIST\\words.txt");
std::string word;
if(file.is_open()){
while(file >> word)//while there are still words in document, store them in string word one at time and execute this code
{
words.push_back(word);//puts the string contained in word in the vecctor
}
}
else{
cout<<"Unable to open file!"<<endl;//error incase it cant open word file
}
file.close();
}
void rand_chars(){//MAKE SURE AT LEAST TWO OF THESE ARE VOWELS!!!
for(int i = 0;i <=5;i++)//only to five because there has to be one vowel at least
randchars[i] = rand() % 26 + 97;
constchar *vowels = "aeiou";//creates one vowel as last value of every set of letters
int con = rand() % 26;
randchars[6] = vowels[rand() % 5];
putchar (toupper(randchars[6]));
}
void play(){
rand_color();
bool test;
int it;
rand_chars();//creates the 7 random characters for the game!
string word_1;
system("cls");//there was a "0" appearing before the text belw for whatever reason. i put this here to erase it
cout<<"Here is your set of words:";
for(int i = 0;i<=6;i++){
cout<<randchars[i];
}
cout<<endl;
cin>>word_1;
//check(word_1);
for(int i = 0;i < words.size();i++){
if (word_1 == words[i]){
correct = true;
switch(word_1.size()){
case 1:
cout<<"No One Letter Words :)";
system("pause");
system("cls");
break;
case 2: score += 200;
break;
case 3: score += 300;
break;
case 4: score += 400;
break;
case 5: score += 500;
break;
case 6: score += 600;
break;
case 7: score += 700;
break;
}
cout<<"CORRECT! Score: "<<score<<endl;
}
}
if (correct == false){
score -=50;
cout<<"Incorrect! Score: "<<score<<endl;
}
system("pause");//only way to do this... its bad but only way for clearscreen
system("cls");
play();
}
your right sorry, i just editied the code above to make it a little easier. i put up the whole thing in case you wanted to urn the project in your IDE t explore the problems, but the problem still likes in the play function