C++ assignment question

Pages: 12
Feb 19, 2013 at 11:22pm
I am new to C++, currently taking a class at my local college, and I'm having trouble figuring this out..

"write a program that inputs a character from the keyboard and the outputs a large block letter "C" composed of that character."

If anyone can help I would really appreciate it!
Last edited on Feb 19, 2013 at 11:22pm
Feb 19, 2013 at 11:23pm
Have you got some code?

We can help, but we can't do assignments for you.
Feb 19, 2013 at 11:25pm
I submitted my assignment once just using cout << "X\n"; to make the letter "C" but my professor said it was wrong. I'm just stumped.
Feb 19, 2013 at 11:32pm
The requirements sound strange. I assume your professor is wanting the uppercase of whatever letter is inputted. In that case, you have a toupper() function you can use. Or you can look at an ASCII chart and see if you notice a relationship between lowercase and uppercase letters, and write the function yourself.

http://www.ascii-code.com/
http://www.cplusplus.com/reference/cctype/toupper/
Feb 19, 2013 at 11:37pm
This is what I had originally done..

cout << " X X X\n";
cout << " X X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << " X X\n";
cout << " X X X\n";

The assignment doesn't mention anything about capital letters or anything like that. Unless this is wrong lol.
Feb 19, 2013 at 11:37pm
the coding got messed up when I pasted it :/
Feb 19, 2013 at 11:40pm
The way you're printing the letter probably isn't wrong - that meets up with his requirements.

However, you need to ask the user for a letter then print the "C" using whatever letter has been entered, rather than "X".

That is, if I have interpreted the requirements correctly.
Feb 19, 2013 at 11:40pm
I think your prof wants you to develop a loop structure to output a multi-line block letter.
1
2
3
4
5
6
7
8
9
10
EEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEE
EEE
EEE
EEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEE
EEE
EEE
EEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEE


So.. something like that, except with the letter C being printed to the screen as a block letter.
Feb 19, 2013 at 11:41pm
Oh, I get what you're saying now.

If that's all your professor had for this assignment, then what you did is just right. He should have more explicit instructors, we're programmers damnit! Not mind readers.

Anyways, he probably is wanting you to use a loop of some kind to generate this. If you notice, there's a pattern in what you did manually.
Feb 19, 2013 at 11:49pm
haha the assignment is out of Walter Savich's "problem solving with C++"

The example says it should look like this..

......X X X
....X......X
...X
...X
...X
...X
....X.....X
.....X X X

I used periods so it would look right lol

but this chapter doesn't say anything about a loop structure, I haven't gotten that far yet :/
Feb 19, 2013 at 11:51pm
Still, though, the assignment wants the letter composed of a character that the user has input.

So, if I input 'Y', it should be:
 YYY
Y   Y
Y
Y
Y
Y   Y
 YYY
Feb 19, 2013 at 11:54pm
I thought that's what I did lol, I can't find how to do that in the chapter for the life of me.
Feb 19, 2013 at 11:55pm
You almost have it. Instead of using X, use a variable. Keep it a char so people don't put in more than one character and screw it up.
Feb 20, 2013 at 12:13am
So if I use something other than 'X' it should be right? Is there anything wrong with my coding? I just used X because that's what the example used..
Feb 20, 2013 at 12:16am
You should use a variable, not a hard coded value.

If your professor didn't explicitly mention using a loop to draw then there's nothing wrong with the way you're drawing, other than the fact that you're using a hard coded value.
Last edited on Feb 20, 2013 at 12:16am
Feb 20, 2013 at 12:35am
Feb 20, 2013 at 12:39am
Nope. Now you're overthinking it. You were on the right track before. Just instead of outputting a hard coded value, output whatever value the user gave you.
Feb 20, 2013 at 12:48am
haha well shit :/ I don't know what you mean by hard coded value. I just used x because that's what the example used. sorry guys, I literally just started this course last Monday
Feb 20, 2013 at 1:34am
It's all good. We were all beginners at some point.
Feb 20, 2013 at 1:42am
Tnobis try this:

int main(){

char X;
cout << "Enter a letter of choice: ";
cin >> X;

cout << " X X X\n";
cout << " X X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << "X\n";
cout << " X X\n";
cout << " X X X\n";
Last edited on Feb 20, 2013 at 1:43am
Pages: 12