searching through vectors and more

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!

P.S. please get the text file from here: http://www.sendspace.com/file/t9tr14

and make sure that the location of the file in the fstream code is changed to where you place it




P.S.S i think the problem lies in the "play" mathod


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
#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>
using namespace 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;

		const char *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();
		}

Last edited on
You realize you can test these sort of things separately and then add what you figure out to your bigger project, right?

Nobody wants to wade through 392 lines of code (even if much of its gratuitous whitespace) for a problem that could be duplicated in 20.

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
Topic archived. No new replies allowed.