How to uppercase selective letters

How do I capitalize the last letter of the last name and first letter of the first name? I have to have a name that has a name that is in alphabetical order "abc def" not "def abc". But i need the out put be "Abc deF".

Also, I need to make the code keep repeating until the name entered is "end end"

Any help?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 /**************************************
Name: Jacob Chesley
Date Created: 2/9/15
Last Modification Date: 2/9/15
Lab Name: Names
File Name: Names
**************************************/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
char name1[50],
	 name2[50];

int input()
{
	
	return 0;
}
int namechange()
{
	return 0;
}
int main()
{
	cout << "Please enter your first and last name." << endl;
	cout << "Press return in between each name." << endl;
	cin >> name1;
	cin >> name2;
	int result,
		FLength,
		LLength;
	char FirstName[50],
		LastName[50];
	//do
	//{
		strlwr(name1);
		strlwr(name2);
		result = stricmp(name1, name2);
		if (result < 0)
		{
			memcpy(FirstName, name1, 50);
			memcpy(LastName, name2, 50);
			cout << "Your first name is " << FirstName << endl;
			cout << "Your last name is " << LastName << endl;
		}
		else
		{
			memcpy(LastName, name1, 50);
			memcpy(FirstName, name2, 50);
			cout << "Your first name is " << FirstName << endl;
			cout << "Your last name is " << LastName << endl;
		}

		FLength = strlen(FirstName);
		LLength = strlen(LastName);

		cout << FLength << endl;

		int toupper(FirstName[FLength - 1]);

		cout << FirstName << endl;
		

	//} while (name1[50] != end && name2[50] != end);
		return 0;
}
closed account (2UD8vCM9)
I wouldn't use a char array to store strings, but if you insist on doing it the way you've started, you could simple do something like this.

All I did was remove the int toupper(FirstName[FLength - 1]); no idea what you were trying to do with that but it was just wrong.

And I replaced that line with
1
2
FirstName[0] = toupper(FirstName[0]);
LastName[LLength - 1] = toupper(LastName[LLength - 1]);




Last edited on
Thank you so much! Thats exactly what I needed.

My only other question, is whenever "end end" or "EnD eNd" or "END END" or any other conversion of the name is entered, the do/while loop would break. Any help there?

PS: The do/while loop was made a comment for the sake of bug testing.
closed account (2UD8vCM9)
Sorry I don't understand what you're trying to do/ I don't understand what the do...while is supposed to be doing.
Im trying to have my program continuously run until i enter "end end".
closed account (2UD8vCM9)
Is this a homework project where you're limited on what you can use, or are you allowed to use strings? Just asking because it will make this a bit simpler.
I'm required to do it in this format yes. However I found how to enter the do/while statement.

"do
{
.....
} while (stricmp(name1, "end") != 0 || stricmp(name2, "end") != 0);

Thank you for the help, it really relieved some stress.
Topic archived. No new replies allowed.