3

I'm having trouble getting my program to compile. The error is happening on line 165-177. All I added was the test for the presence of letters and I got an error, hope you can help! Full Code http://pastebin.com/embed.php?i=WHrSasYk

(Attached below is code)

do
{
  cout << "\nCustomer Details:";

  cout << "\n\tCustomer Name:";
  cout << "\n\t\tFirst Name:";
  getline (cin, Cust_FName, '\n');
  if (Quotation::Cust_FName.length() <= 1)
    ValidCustDetails = false;
  else
  {
    // Error line 165!
    for (unsigned short i = 0; i <= Cust_FName.length; i++)
      if (!isalpha(Quotation::Cust_FName.at(i)))
        ValidCustDetails = false;
  }
  cin.ignore();
  cout << "\t\tLast Name:";
  getline (cin, Cust_LName, '\n');
  if (Cust_LName.length () <= 1)
    ValidCustDetails = false;
  else
  {
    // Error line 177!
    for (unsigned short i = 0; i <= Cust_LName.length; i++)
      if (!isalpha(Cust_LName.at(i)))
        ValidCustDetails = false;
  }
  cin.ignore();
}
while(!ValidCustDetails);
hubatish
  • 5,070
  • 6
  • 35
  • 47
Steven O'Riordan
  • 61
  • 1
  • 1
  • 2

2 Answers2

10

These lines are your problem:

for (unsigned short i = 0; i <= Cust_FName.length; i++)
for (unsigned short i = 0; i <= Cust_LName.length; i++)
//                                              ^^

std::string::length is a function, so you need to invoke it with parens:

for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)
cdhowie
  • 158,093
  • 24
  • 286
  • 300
3

I suspect that Cust_LName is a std::string so you should add () after length :

Cust_LName.length()
Jarod42
  • 203,559
  • 14
  • 181
  • 302