I'm working my way through the C++ tutorials and I'm stuck on character arrays. Basically, I don't understand how a user can input a sentence into the program and then how to store that sentence in a variable, ready to be called in a cout<< line.
Here is a piece of code I'm trying to work on (to no avail). The problem here isn't identical but an answer to the previous question will probably help answer this one.
Why doesn'tCode:#include <iostream> //For cout using namespace std; int main() { int monstype; char monsdescription[35]; cout <<"please choose the monster you wish to fight:\n1. Big hairy ugly thing\n2. Small and easy on the eyes\n3. Medium size, much the same as you!\n"; cin>> monstype; if (monstype == 1){ monsdescription = "Big hairy ugly thing"; } else if (monstype == 2){ monsdescription = "Small and easy on the eyes"; } else{ monsdescription = "Medium size, much the same as you!"; } cout <<"You have chosen "<< monstype <<", "<< monsdescription <<""; cin.get(); }
work? The error line says:Code:if (monstype == 1){ monsdescription = "Big hairy ugly thing"; }
incompatible types in assignment of 'const char [27]' to 'char [35]'
or
with an error line :Code:else{ monsdescription = "Medium size, much the same as you!"; }
invalid array assignment



LinkBack URL
About LinkBacks



