Hi all. I am trying to create a function to check if a string is a pangram or not. I think I have good start on it, but I can't figure out how to check if the characters in the string are unique. I have to do this recursively with no global or static variables. I created a counter variable the gets incremented every time the isPangram function gets called. I figure since there are 26 letters in the alphabet, if I can figure out how to insert 26 unique characters into a new string from the old string that would make it a pangram. Here is my code so far. Any pointers would be grateful.

#include <iostream>
#include <string>
using namespace std;

bool isPangram(string str, int counter, int last_index)
{
    if(counter >= 26)
    {
		return true;
	}
	else
	{
	    return isPangram(str, ++counter, --last_index);
	    //return false;
	}
}
bool isPangram(string str)
{
   return isPangram(str, 0, str.length() - 1);
}

You could have 26 integers variables each assigned to a letter or a boolean array, whenever you parse one of the letters you change the appropriate integer to 1 and have a checking function to make sure that if any of the integers is above 1 you reject it and if your looping switch them all to 0 at the end.

I cannot use any global or static variables and it has to be done recursively.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.