It lets me continue the loop but it won't let me enter a sentence the second time??

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

int main()
{
    char c, response;
    int Uc = 0, Dc=0, Vc=0, Wc=0;
    string vowels("aeiouAEIOU");

    cout << "I can count the number of upper case, lower case, vowels and words" << endl; 
do
{
    cout << "Enter a sentence: ";
    cin.get(c);

    while(c != '\n')
    { 
        {
        if(isupper(c))  
            Uc++;  
        if(isdigit(c)) 
            Dc++; 
        if(vowels.find(c) != string::npos)
            Vc++;
        if (isspace(c))
            Wc++;

        cin.get(c);
        } 
    }

     cout << setfill ('.');
     cout << "  Number of uppercase letters: " << Uc << endl; 
     cout << "  Number of digits: " << Dc << endl; 
     cout << "  Number of vowels: " << Vc << endl;
     cout << "  Number of words: " << Wc << endl;

     cout << "CONTINUE(y/n)? ";
     cin.get(response);

} while(response == 'Y' || response=='y') ;
    cout << endl;

    system("pause");
    return 0;
}

Dani AI

Generated

As explained, the immediate cause is a leftover newline from the y/n response: that newline gets read by the next cin.get(c) so the inner loop instantly sees '\n' and the program never waits for a new sentence. There are several fixes (discard the leftover newline, use std::ws, or read whole lines). A robust, simple approach is to switch to line‑oriented input for both the sentence and the response so nothing is left behind.

A compact, safe pattern (read a full line, reset counters each time, and count words by detecting transitions) looks like this:

#include <iostream>
#include <string>
#include <cctype>

std::string line;
while (true) {
    std::cout << "Enter a sentence: ";
    if (!std::getline(std::cin, line)) break;        // reads whole line

    int Uc = 0, Dc = 0, Vc = 0, Wc = 0;
    bool inWord = false;

    for (char ch : line) {
        unsigned char uch = static_cast<unsigned char>(ch);  // safe for ctype
        if (std::isupper(uch)) ++Uc;
        if (std::isdigit(uch)) ++Dc;
        char low = static_cast<char>(std::tolower(uch));
        if (low=='a' || low=='e' || low=='i' || low=='o' || low=='u') ++Vc;

        if (!std::isspace(uch) && !inWord) { ++Wc; inWord = true; }
        if (std::isspace(uch)) inWord = false;
    }

    // print Uc, Dc, Vc, Wc...
    std::cout << "CONTINUE(y/n)? ";
    std::string resp;
    std::getline(std::cin, resp);                       // safe prompt for answer
    if (resp.empty() || (resp[0] != 'y' && resp[0] != 'Y')) break;
}

Notes tied to 's original code: counters should be reset each iteration (declare them inside the loop) or they will accumulate across repeats; counting words by incrementing on isspace actually counts spaces, not words—the transition method above gives real word counts; always cast char to unsigned char before calling <cctype> functions to avoid undefined behavior. If changing to getline is not desired, read the response with formatted extraction (cin >> response) or explicitly discard the leftover newline (e.g. ignore)— already mentioned this—but prefer line-based I/O for clarity and fewer surprises.

The problem is that cin.get(response); is leaving an '\n' in the buffer so when you call cin.get(c); at the beginning of the loop it pulls in the '\n'. Since '\n' stops the inner loop it never gets executed and then you are asked to continue again. To fix this you need to get rid of the '\n' in the buffer. You can use a simple hack and use cin.get() after cin.get(response); which will eat the '\n' and you can enter another sentance. I prefer to use ignore() and I use it as

cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
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.