1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
SECOND FUNCTION
int k=o;
while(k<(set.length()-1) && x==false && z==false) // this function checks if there is any duplication in set
{
int y=set.find(set.substr(k), (k+1)); k++;
if(y!=string::npos)
{
cout<<"You cannot repeat a character in your set!"<<endl;
cout<<name<<", please enter another character set: "; cin>>set; IfExit(set, x); z=true;
}
else
x=false;
}
|
NOTES:
-Conditions of functions are true. In big function, which these little ones are involved, i check a given string if it has any punctuations, numbers, duplications etc. if there is, i ask user to re-enter another set.
-i used a given header file and a cpp file, they are both called strutils.
-IfExit() is a function which i wrote in my own cpp file. way it works is whenever user enters something like eXit, EXIT, ExiT etc, program shuts off, it changes x's value to true or false in terms of keeping program run or shut it down. I also checked it, it works correctly.
I figured out what was wrong in first func. :)
In sec. func. i check every single letter, except last one, if there is any other same letter. ps: i only check right side of the chosen letter. i.e set is "asdfgh", lets say we are checking d: function starts checking from f, at least what i tried to do was this.
i tried to change their inner condition(yet i still believe i wrote them down true:p). sometimes i did make them work but they worked in a wrong way. i.e i entered "ead" and program said u cannot repeat a character in your set!
Also i am having problems with storing words which i ask user to enter in a while loop. i defined 2 string: wordlist and word. i ask user to enter a word in a while function, if it is entered correctly, i ask for another till user enters "end". i defined wordlist+=word. yet i think it stores words as one. i couldn't figure out how to store them as word 1, word 2 -or in any other way- to use them separately after on the program.
any help will be appreciated:)