Does anyone know what the differences are between compiling in Unix and Visual C++?
My code works in Visual C++ but it doesn't in Unix. When compiling it says:
In function 'void RuleTwo(basic_string<char,string_char_traits<char> ,__default_alloc_template<false,0>>,
basic_string<char,string_char_traits<char>,__defau lt_alloc_template<false,0>>)'
and
unused varialbe 'int len' (within the same function)
Anybody know how I could fix this? Thanks in advance. Here is the code if you need it:
Code:
void RuleOne(string word, string target1)
// Pre-condition: String has been entered by user and starts with the
// following letters: TH, CH, SH, PH, WH, QU.
// Post-condition: Returns single string to the screen with the first two
// letters removed from the front and added to the end of
// the word and the letters AY added to the end of the string.
{
string temp;
int len = word.length()-1; // Index of last character
if (target1=="TH" || target1=="th" || target1=="tH" || target1=="Th" ||
target1=="CH" || target1=="ch" || target1=="cH" || target1=="Ch" ||
target1=="SH" || target1=="sh" || target1=="sH" || target1=="Sh" ||
target1=="PH" || target1=="ph" || target1=="pH" || target1=="Ph" ||
target1=="WH" || target1=="wh" || target1=="wH" || target1=="Wh" ||
target1=="QU" || target1=="qu" || target1=="qU" || target1=="Qu")
{
temp = word.substr(2,len);
word = temp + target1 + "AY";
cout << word << endl;
} // End if
} // End function RuleOne
void RuleTwo(string word, string target2)
// Pre-condition: String has been entered by user and starts with the following
// letters: A, E, I, O, U.
// Post-condition: Returns original string to the screen with the letters AY
// added after the string.
{
string temp;
int len = word.length()-1; // Index of last character
if (target2=="A" || target2=="a" ||
target2=="E" || target2=="e" ||
target2=="I" || target2=="i" ||
target2=="O" || target2=="o" ||
target2=="U" || target2=="u")
{
word += "AY";
cout << word << endl;
} // End if
} // End function RuleTwo
void RuleThree(string word, string target1, string target2)
// Pre-condition: String has been entered by user and does not fit RuleOne
// or RuleTwo
// Post-condition: Returns single string to the screen with the first letter
// removed from the front and added to the end of
// the word and the letters AY added to the end of the string.
{
string temp;
int len = word.length()-1; // Index of last character
if (!(target1=="TH" || target1=="th" || target1=="tH" || target1=="Th" ||
target1=="CH" || target1=="ch" || target1=="cH" || target1=="Ch" ||
target1=="SH" || target1=="sh" || target1=="sH" || target1=="Sh" ||
target1=="PH" || target1=="ph" || target1=="pH" || target1=="Ph" ||
target1=="WH" || target1=="wh" || target1=="wH" || target1=="Wh" ||
target1=="QU" || target1=="qu" || target1=="qU" || target1=="Qu" ||
target2=="A" || target2=="a" ||
target2=="E" || target2=="e" ||
target2=="I" || target2=="i" ||
target2=="O" || target2=="o" ||
target2=="U" || target2=="u"))
{
target2 = word.substr(0,1);
temp = word.substr(1,len);
word = temp + target2 + "AY";
cout << word << endl;
} // End if
} // End function RuleThree
void KeepGoing()
// Pre-condition: User has entered a choice.
// Post-condition: Starts the program again if user enters Y or y. Ends the
// program if user enters anything else.
{
char ch;
string word, target1, target2;
cout << "\nWould you like to continue? (Enter Y for yes): ";
cin >> ch;
if (ch=='Y' || ch=='y')
{
cout << "\nPlease enter another word: ";
cin >> word;
cout << word << " = ";
target1= word.substr(0,2);
target2= word.substr(0,1);
RuleOne(word, target1);
RuleTwo(word, target2);
RuleThree(word, target1, target2);
KeepGoing();
} // End if
else
{
cout << "\nThank you for using this program.\n\n";
} // End else
} // End function KeepGoing
int main()
{
string word;
string target1, target2;
cout << "This program will translate one word from English to PigLatin.\n\n";
cout << "Please enter a word: ";
cin >> word;
cout << word << " = ";
target1= word.substr(0,2);
target2= word.substr(0,1);
RuleOne(word, target1);
RuleTwo(word, target2);
RuleThree(word, target1, target2);
KeepGoing();
return 0;
} // End Main