Otto von Bismarck
Otto von Bismarck

Reputation: 1

Problem with switch-statement "too many characters int the char constant"

I have some problem with the switch-statement and I don't know how to resolve it:

    string phrase;

    cout << "enter a phrase:\n";
    getline(cin, phrase);
    for (unsigned int i = 0; i < phrase.length(); i++)
    {
        switch (phrase[i])
        {
        case '-----':
            cout << "0";
            break;
        }
    }

It gives me an error that says "too many characters int the char constant". Can somebody tell me how to resolve it? Thanks in advance.

Upvotes: 0

Views: 243

Answers (1)

Muhammad Arslan
Muhammad Arslan

Reputation: 376

string phrase;
int sum=0;
cout << "enter a phrase:\n";
getline(cin, phrase);
for (unsigned int i = 0; i < phrase.length(); i++)
{   
    
    switch (phrase[i])
    {
    case '-':sum+=1;
        if (sum%5==0)
        cout << "0";
        break;
    }
}

1

Upvotes: 1

Related Questions