Character/String types

Hello, I'm trying to create a program that will ask the user to input letters and the program will print the letter in between those 2. Like for example, I enter A and E. How should I go with this? What data type should I use? Loops? Any insight on what logic should I use? functions etc.

I don't know where to start.

Last edited on
you can use ascii value ... use toascii() function in ctype.h
Well, I tried that but it's just showing the character codes based on the ascii table which wasn't my goal in the first place.

1
2
3
4
5
6
7
8
9
char a, b;

	cin.get(a);
	cin.get(b);

	cout << toascii(a, b);

	system ("pause");
	return 0;
Last edited on
toascii just gives the number representation.

Actually this assignment is pretty easy basically here is what you need to do

1)declare 3 characters , input1 , input2 , and a temp variable (temp)
2)ask the user to input two letters (chars) using std::cin (or cin.get() ). cin >> input1;
3) use a loop to iterate starting from a letter after the first until it reaches the last letter you can use a while loop or manipulate a for loop.
for( temp = input + 1; temp < input2; ++temp ) cout << temp;

(std:: is scoping when you don't use "using.")

http://ideone.com/A0cp0s
I would do this rather than cin.get()
cin >> a >> b;

Then use either a while or for loop to repeatedly:
add 1 to a, and if it is less than b, cout << a;

One problem, if a is greater than b (say a ="F" and b = "A") the result may not be as expected, in that case you could swap the values of a and b before the loop begins.
Gotcha.

Any other errors I should look out for? Thanks by the way.
1
2
3
4
5
6
7
if (a>b)
	{
	   tempswap=a;
	   a=b;
	   b=tempswap;

	}
lower and uppercase letters as I mentioned in my code. They have completely different ascii values.
Ok, last question how does the computer know that A is greater than B or C or D or the other way around? I'm guessing it's not the character codes because A is 65?

EDIT:

AHH I completely messed sorry for this stupid question. I figured it out thanks.
Last edited on
Topic archived. No new replies allowed.