Displaying a sequence of letters

I'm completely stuck with this program. I have to read in two letters and display the sequence from the first letter to the last.

For example: Input: "A C" Output: "A B C :"
Input: "A A" Output: "A :"
Input: "Z A" Output: ":"

This is what I have so far, but it's basically nothing. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
   char letter;

   for ()                              
   {
      cin >> letter;
      cout << letter << ' ';     // DO NOT DELETE.
   }


   cout << ':' << endl; return 0; // DO NOT MODIFY, MOVE or DELETE.
}
1
2
3
4
5
for ()
	{
		cin >> letter;
		cout << letter << ' ';     // DO NOT DELETE.
	}


Cant do that. You need to give your for-loop a condition.

Also. I didint really understand what you want it to output.

Edit: Give an example of what you input, and What you Want it to output.
Last edited on
I want it to output the two letters that are read from the user, along with every letter in between.

For example: Input: "A C" Output: "A B C :"
Input: "C G" Output: "C D E F G :"
Input: "A A" Output: "A :"
Input: "Z A" Output: ":"
Then you need to use arrays. A char array that has every single letter in it.

char letters[27] = {'A', 'B', 'C'....}

Then you have to check if any of the inputed letters, match two of the letters inside the array.
And then print out everything between those 2 letters.
Last edited on
Is there another way to do it? I know there has to be a for loop somewhere in the program because that much was given by the professor. And we haven't gone over arrays yet in class, so I doubt he'd want us to use one.
Last edited on
Are you sure you didnt misunderstand the assignment?
I'm pretty sure. This is exactly what was given to me:

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
// ------------------------------------------------------------------
// Function: Read in two letters.
//           Display the sequence from the first letter to to last.
//
// Examples:  input A C  ==> output: A B C :
//            input A A  ==> output: A :
//            input Z A  ==> output: :
//
// WARNING:   DO NOT PROMPT FOR INPUT.
// ------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
   char letter;



   for
   {

      cout << letter << ' ';     // DO NOT DELETE.
   }


   cout << ':' << endl; return 0; // DO NOT MODIFY, MOVE or DELETE.
}
Im confused. He clearly says input A C etc... but then says DO NOT PROMPT FOR INPUT. What?
When he says that he's meaning don't print out a statement saying "Please enter two letters" or something like that. It interferes with the grader.
Maybe something like this .. ?

1
2
3
4
5
6
7
8

char letter[2] ;

cin >> letter[0] >> letter[1] ;

for(char i = letter[0] ; i <= letter[1] ; i++)
cout << i << ' ' ;
And we haven't gone over arrays yet in class, so I doubt he'd want us to use one.

Apparently they cant use arrays @obscure. And it also says no prompt for input, so they cant use cin either...
That worked. Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
   char first, last;
   cin >> first >> last;

   for (int i = first; i < last; i++)                              
   {
      cout << letter << ' ';     // DO NOT DELETE.
   }


   cout << ':' << endl; return 0; // DO NOT MODIFY, MOVE or DELETE.
}
Last edited on

Apparently they cant use arrays @obscure. And it also says no prompt for input, so they cant use cin either...


Ah ... ! I don't noticed about the arrays .. Sorry ..
So (steezedq) pick the (Faison) solution because it doesn't contain an array ..

Second thing about the prompt ... maybe he mean to not use a ( message)
before (cin) ..
Because there is no why other than (cin) to read input ( for him ) ..







@obscure. I did consider that, and I guess you're right but. His prof said

// WARNING: DO NOT PROMPT FOR INPUT.

does his professor have coutophobia? or some shit? Becuase that is one hell of a pointless warning.


Maybe input from the command line arguments ??
But he didn't mention that .. So maybe he haven't known it yet ...
Yes ... something weird ..
Topic archived. No new replies allowed.