abbreviate the first 2 letters of the name using #<cctype> / #<string>

The program reading the name of the state and abbreviate the first 2 letter toupper(c). If there are two words in the name, it will read the start letter of each separate word.

I do not know what I do wrong, but the program doesn't put a properly output. Please could anybody help? I am deeply appreciate for your helps.

Great thanks in advanced.

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
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
	string name,twoname,YesNo;
	do{
	cout<<"Enter a state name: ";
	getline(cin,name);
	{
	int n=name.find(' ');
	if (n==-1)
	{name[0]=toupper(name[0]);
	name[1]=toupper(name[1]);
	cout<<name[0]<<name[1]<<endl;
	cout<<"Continue (Y/N)?: ";
	cin>>YesNo;}
	else
	{name[n+1]=toupper(name[n+1]);}
	cout<<name[0]<<name[n+1]<<endl;
	cout<<"continue (Y/N)?: ";
	cin>>YesNo;}
	cin.ignore();
	}
	while (YesNo=="y" || YesNo=="Y");

	system("pause");
	return 0;
}
Try fixing the indentation in your file. I said something similar here on this post:
http://cplusplus.com/forum/beginner/79642/#msg428968

What I see is extra curly braces you do no need, and I also see that some curly braces that are necessary are misplaced.
Topic archived. No new replies allowed.