Valid Input: xxxx-xxxx-xxxx-xxxx or xxxx xxxx xxxx xxxx (x being digit 0-9)
Valid Output: Valid, Invalid
My Output: Nothing (Press any key to continue ...)
So I thought I had my conditions right where it would tell me whether or not my input is valid or not. But I get neither. What am I missing?
#include <iostream>
#include <string>
using namespace std;
bool isvalid(string& strDest, const string& strSource)
{
string strTemp;
strDest = "";
for (int i = 0; i < strSource.length(); i++)
{
if (isdigit(strSource[i]))
{
strTemp += strSource[i];
}
else if (strSource[i] != '-' && strSource[i] != ' ') {
break;
}
}
First of all, please use code tags. Click the "<>" button in the format options and paste your code between the tags. It will make it much easier for us to read your code.
When you validate strValidate, the argument is empty. So the validate() function will always return false.
strSource is also an empty string, so it's length is 0. The inner loop is never entered, and nothing prints.