Trouble with reversing letters w/o using string

When compiled, it only gives me added numbers of letter numerical value. What am i doing wrong?
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
#include<iostream.h>
#include<cstdlib>
#include<stdlib.h>
main()
{
	char word [3];
	int a;
	char b;
	char c;
	char d;
	char e;
	char f;
	char g;
	char h;
	char i;



cout<<"Press one to reverse the letters of a word."<<endl;
cout<<"Press two to invert the case of the letters."<<endl;
cout<<"Press three to exit"<<endl;
cin>>a;
{
	if (a=='1')
cout<<"Please input a four letter word"<<endl;
cin.get(word,3);
cin.ignore(80,'\n');
system("cls");
b= (word[0]);
c= (word[1]);
d= (word[2]);
e= (word[3]);
cout<<word [3]<<endl;
}
{
	if (a=='2')
cout<<"Please input a four letter word"<<endl;
cin.get(word,3);
cin.ignore(80,'\n');
system("cls");
f=int (word[0]);
g=int (word[1]);
h=int (word[2]);
i=int (word[3]);
f=f-32;
g=g-32;
h=h-32;
i=i-32;
cout<<f+g+h+i<<endl;
}
{
	if (a=='3')
 exit(1);
}
return 0;
}
Last edited on
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.

Do you want to use C, or C++? It isn't clear from your post.

In either language, char is a numeric type that just gets special treatment in some cases. The + operator performs addition, not concatenation.
Topic archived. No new replies allowed.