dimanche 17 octobre 2021

C++ First letter of every word must be uppercased

I'm a student and new to programming

I'm trying to make every first letter of every word uppercased and the rest lowercased.

The output currently is that only the first word is being printed even though I'm typing in 2 or more words.

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int i;
    char str[100];
    char rev;
    int len = 0;

    cout << "Enter a string: ";
    cin >> str;
    
    len = strlen(str);
    
    for (i = 0; i < len; i++)
    {
        if (i == 0)
        {
            str[i] = toupper(str[i]);
        }
        else
        {
            str[i] = tolower(str[i]);
        }
        cout << str[i];
    }
}

Aucun commentaire:

Enregistrer un commentaire