0

I need the first and last names to be capitalized, so if the user inputs a lowercase, it'll change it to uppercase when it's displayed. But it's just the ASCII and I'm not sure how to fix it. Thanks!

#include <iostream>
#include <cctype>

using std::cout;
using std::cin;
using std::toupper;

char firstname[15],
     lastname[15];
int f = 0,
    l = 0;

int main()
{
    cout << "Enter your last name: " ;
    cin >> lastname;

    cout << "Enter your first name: " ;
    cin >> firstname;

    f = toupper (firstname[0]);
    l = toupper (lastname[0]);

    cout << "Welcome " << firstname << " " << lastname << '\n';
    cout << "Access granted. Please proceed." << '\n';

return 0;
}
2
Contributors
1
Reply
21
Views
3 Years
Discussion Span
Last Post by Suzie999
0

Don't know if thisa is best way, but appears to work for me.

#include "stdafx.h"
#include <iostream>
#include <cctype>

using std::cout;
using std::cin;
using std::toupper;
char firstname[15],
     lastname[15];

int main()
{
    cout << "Enter your last name: " ;
    cin >> lastname;
    cout << "Enter your first name: " ;
    cin >> firstname;
    firstname[0] = toupper (firstname[0]);
    lastname[0] = toupper (lastname[0]);
    cout << "Welcome " << firstname << " " << lastname << '\n';
    cout << "Access granted. Please proceed." << '\n';
return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.