Q:

C++ cout prints out same string a few times

My code has an if else statement which verifies whether an input is a string full of alpha characters. 
The code works but the cout << original << "\n"; part prints out the result 5 times. I think the root of the issue lies within the for (std::string::iterator it=original.begin(); it!=original.end(); ++it) line, specifically the ++it bit.
Below is the code:
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <locale>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    std::locale loc;
    std::string original;
    std::cout << "Welcome to the English to Pig Latin translator!\n";
    std::cout << "Type a word you wish to translate:\n";
    std::getline(std::cin, original);
    std::cout << "Your word: " << original << "\n";
    for (std::string::iterator it=original.begin(); it!=original.end(); ++it)
    {
        if (original.length() > 0 && std::isalpha(*it,loc) )
        {
            std::string word;
            std::transform(original.begin(), original.end(), original.begin(), ::tolower);
            cout << original << "\n";
        }
        else
        {
            std::cout << "Please enter a valid word." << std::endl;
        }
    }

    system("PAUSE");
    return 0;
}

This link is a screenshot of my CLI output:
http://gyazo.com/5b9cea385794fecc39ed578b539a84c3

A:

It's printing five times because "hello" is five characters long. Your for loop is running once for each character in the string.

A:

Your code is not correct. It checks for each character rather than the entire string.
Change it to:
bool alphaString = true;
for (std::string::iterator it=original.begin(); it!=original.end(); ++it)
    {
        if (! std::isalpha(*it,loc) )
        {
            std::cout << "Please enter a valid word." << std::endl;
            alphaString = false;
            break;
        }
    }
if ( alphaString ) {  
  std::transform(original.begin(), original.end(), original.begin(), ::tolower);
  cout << original << "\n";
}

