I have been having various issues trying to figure out a very trivial problem. I've re-written this code now several times and used many different condition statements etc... One issue that i'm having right now is the input for the variable "paragraph" not being available, the paragraph input is skipped and thus the rest of the code skipped, amongst many other things. I haven't added everything yet because i'm still trying to work out the issues mentioned above.

cout << "\nWould you like to continue? 'y' for yes and 'n' for no...\n";
    cin.get(response);

    while ((response != 'n') || (response != 'N'))
	{   
		while ((response != 'y') && (response != 'Y') && (response != 'n') && (response != 'N'))
		{
           cin.clear();
		   cin.sync();
		   
		   cout << "\nInvalid response, would you like to continue?" << endl;
		   cin >> response;
		}

        
		cout << "\nEnter a paragraph press 'enter' when done:\n";
        getline(cin,paragraph);
		
	
		
	    nonblank = paragraph.length();

        uppercase = 0;
	    lowercase = 0;
	
	    while (count <= nonblank)
			{
				if (paragraph >="A" && paragraph <="Z")
				{
				uppercase += 1;
				}

				count++; 
			}



	
			while (count <= nonblank)
			{
				if (paragraph >="a" && paragraph <"z")
				{
				lowercase += 1;
				}

				count++;
			}
	

		nonblank = uppercase + lowercase;

			cout << "\nThe number of uppercase letters is "<< uppercase << endl;
		    cout << "\nThe number of lowercase letters is "<< lowercase << endl;
			cout << "\nThe number of nonblank characters is "<< nonblank << endl;

			cout << "\nWould you like to continue?\n";
			cin.get(response);

			("cls");

	}
	
		


	return 0;//checks if program executed correctly

}//end function main

}//end function main

Yes a sting is an STL container so you can use all the usual STL algorithms on it like for instance count_if.

Also you should use the functions defined in the header local, specifically is rather than the value comparisons if (paragraph >="A" && paragraph <="Z") to check for the case ( http://www.cplusplus.com/reference/std/locale/ctype/is/ ).

Use these to facilities and you can reduce both of you while loops to 1 line of code and a 1 line function (predicate).

Your calculation of nonblank is faulty you have assumed that all characters that are not letters are blank but clearly punctuation and digits are not blank and not letters.

Yes a sting is an STL container so you can use all the usual STL algorithms on it like for instance count_if.

Also you should use the functions defined in the header local, specifically is rather than the value comparisons if (paragraph >="A" && paragraph <="Z") to check for the case ( http://www.cplusplus.com/reference/std/locale/ctype/is/ ).

Use these to facilities and you can reduce both of you while loops to 1 line of code and a 1 line function (predicate).

Your calculation of nonblank is faulty you have assumed that all characters that are not letters are blank but clearly punctuation and digits are not blank and not letters.

I took out a lot and made the code more basic inorder to see where the issues were, the issue the issue that i was primarily trying to resolve is why input isn't being taken for the paragraph string. When ever i run the program it takes the "response", if the response is correct then it skips everything and goes to the end of the loop to the question "would you like to continue"? Ofcourse commenting things out is much more simple, but i rewrote the whole thing and to save time just left out things that i knew would work when i plan to add them after i resolve the issues i'm having. I know to compare uppercase and lowercase to blank space characters '\n' '\t' ' ', but thats not the problem i've been having.

Sorry I completely overlook your initial description of your problem.

You haven't actually said how response is declared but assuming char response; then the problem is that when you read response data is left in the input buffer, this data is then read into paragraph in the getline statement.

The way stdin (the console) works normally is that the program does not see anything until the user presses enter. You ask for a yes/no (y/n) response the user presses y and enter and after this the input buffer contains 'y\n' (\n being a newline character).

You read the y into response and leave the '\n' in the buffer so when you call getline, which reads the next line from stdin or put another way all the characters upto the next line the first thing it sees is '\n' so it returns empty.

This is easy to test without altering your program at the prompt "would you like to continue" type in something like "yYes I would" followed by enter and you should find the program doesn't stop but paragraph contains "Yes I would".

You need to make sure you read anything left over in the input buffer after reading in response.

No problem but i appreciate the help, i was having multipe issues but i think the problemse were with the condition statements, for some odd reason when i changed them around then the input was recieved, now i can actually modify the if statements. I took your advice for getting rid of one of the loops and the code looks better. Thanks for the help. I'll make sure to watch the values for the variables char and string in the locals (which i should have done from the beginning but didn't because of minor frustrations) window to see if the value for char reads into string like you suggested, thanks a lot for the help.

This article has been dead for over six months. Start a new discussion instead.