question, this should work right? i only got one error while compiling so i really couldn't test it. can someone please run it and explain to me what i did wrong?
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
void wait_for_enter();
void palindrome(string line);
string reverse(string line);
string verify(string reversed);
int main()
{
string line;
ifstream scrabble("/Users/andrewassaly/Desktop/scrabble_words.txt");
if (!scrabble.is_open())
{
cout << "Error, cannot find file" << endl;
wait_for_enter();
return 13;
}
while (!scrabble.eof())
{
scrabble >> line;
palindrome(line);
}
wait_for_enter();
return 0;
}
///////////////// Palindrome /////////////////////
void palindrome(string line)
{
string reversed;
reversed = reverse(line);
verify(reversed);
wait_for_enter();
}
///////////////// reverse///////////////////////
string reverse(string wordin)
{
string wordr;
int i, j;
i = 0;
j = wordin.size() -1; // -1 because an array starts counting at 0, not 1
wordr = wordin;
/* this while loop reverses the wordin
it does this by taking the letter at i and making it equal to the letter
at j*/
while (j >= 0)
{
wordr[i] = wordin[j];
i++;
j--;
}
return wordr;
/////////////////////verify ///////////////////////
void verify(string reversed, string wordin)
{
if (reversed == wordin)
{
cout << wordin << " is a palindrome!!!!" << endl << endl;
}
else
{
cout << wordin << " is not a palindrome!!!" << endl << endl;
}
}
///// i need this code for mac, other system paus does not work/////
void wait_for_enter()
{
cout << "press <enter> to continue...";
cin.clear();
string line;
getline( cin, line);
}