C++ Application

Hello,
I'm making a basic console application that allows the user to create an animal species, create a pet of that species, then teach it tricks (that make the program print a message to the screen). Whenever I test it though, it terminates at a certain point, every time. It also only displays one letter out of a string.

This is the code:
1
2
3
4
5
6
7
8
9
void defineTrick()
{
    cout<<"What can "<<petName<<" do?";
    cin>>petTrick[petTricksProgress][0];
    //This next line produces the error I think.
    cout<<"What does "<<petName<<" do when it "<<petTrick[petTricksProgress][0]<<"s?";
    cin>>petTrick[petTricksProgress][1];
    petTricksProgress++;
}


Whenever I run it works fine until I tell it the name of the trick. Say I enter "Meow". It'll print "What does <name> do when it Ms?". Then it says the normal "Process returned 1 (0x1) execution time : 5.109 s
Press any key to continue.", skipping the next few lines!

Any help would be appreciated. I'm relatively new to C++.

If you need more detail and/or code tell me, I'll gt back to you with it.

Thanks,
hnefatl
What type is petTrick and what type is petTricksProgress?
petTrick is char petTrick[101][101]
petTricksProgress is int.

petTricksProgress increments in other functions to create different commands.

I could paste the whole code if it would help?
petTrick is a two-dimensional array. Each element in that array is a char. One single char.

What happens when you try to write "Meow" into a single char? It doesn't work. You cannot write more than one char into a single char. If you want to be able to write more than one char, use proper C++ string types instead of char
Ok, thanks. I didn't know multidimensional arrays could only hold a single char.
It's nothing to do with it being a multidimensional array. It's because you made an array of type char. Each char can only hold one char. That's what a char is.

C-style strings are arrays of char, but when dealing with them you have to place each letter in each element. Functions often use char pointers and pointer arithmetic to make this easy, but there's no escaping it - when you make an object of type char, you can put one char in it.
Topic archived. No new replies allowed.