spanish program not accepting multiple letters.

i'm making this spanish conjugator for class.
and i cant seem to get how to make multiple letter variables.
can anyone tell my what i'm doing wrong?
it's kinda urgent.

here is the code so far.

#include <iostream>
using namespace std;

int main () {


char verb;
cout << "Enter the base of the verb you would like to conjugate" <<endl;
cin >> verb;
cout << "Thank you" <<endl;

char gruppe;
cout << "is it an ir, er or ar verb?" <<endl;
cin >> gruppe;
cout << "Thank you" <<endl;

char pronomen;
cout << "now who does it (yo, tú, él, ella, usted, nosotros, vosotros, ellos, ustedes" <<endl;
cin >> pronomen;
cout << "thank you" <<endl;

if (gruppe == 'ir'){
if (pronomen == 'yo'){
cout << verb << "o" <<endl;
}
if (pronomen == 'tú'){
cout << verb << "es" <<endl;
}
if (pronomen == 'él'){
cout << verb << "imos" <<endl;
}
if (pronomen == 'ella'){
cout << verb << "imos" <<endl;
}
if (pronomen == 'usted'){
cout << verb << "imos" <<endl;
}
if (pronomen == 'nosotros'){
cout << verb << "ís" <<endl;
}
if (pronomen == 'vosotros')
cout << verb << "en" <<endl;
}
}
You should do a bit of studying on character types first.

char is a single character type. If you want to get a sentence or word, you need to use either char* or char[N] (array of characters, also known as a c-string, where N-1 is the maximum number of characters), or string (though you'll then need to #include <string> ).

If you use char*, you then need to use char* str = new char[N] where N-1 is the maximum number of characters that'll fit. In the if's, it then also has to become if(!strcmp(str,"ir")). At the end of the code, you'll then need a delete[] str;

Using strings, everything is simpler. All the memory allocation is done for you and it has an overloaded == operator which means that simply doing
1
2
 string str="bla";
if(str=="ir")

will work just fine. However, <string> is a purely C++ method, so it might not be valid for your class if all you're taught is C (that was my case).

Also note that I used double-quotes instead of single-quotes. That's because single-quotes stand for single characters. For two or more characters, you need to use double-quotes, which is the representation of c-strings.
Last edited on
Wasabi, the header file <string> is deprecated. He needs to use <cstring>.
Neither <string> nor <cstring> is deprecated.
<string> is for std::string and <cstring> denotes the header that is named string.h in C.
packetpirate wrote:
Wasabi, the header file <string> is deprecated. He needs to use <cstring>.

WHAT?!?

Are you confusing <string.h> with <cstring> (the former being identical but deprecated indeed)?

EDIT: I'm late.

-Albatross
Last edited on
i played around with the strings and stuff, and i got it to work.
Thank you guys!
Topic archived. No new replies allowed.