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;
    }
}

Dani AI

Generated

Short answer: the problem is the use of char for multi-letter input and comparing with things like 'ir' or 'yo'. A char holds a single character; 'ir' in single quotes is a multi-character character literal (implementation-defined) and is not the same as a string. As and pointed out, use strings and compare with string literals (double quotes). Below is a concise, practical approach that fixes the logic and keeps the code maintainable.

Read the full infinitive (e.g. "hablar"), normalize to lowercase, detect the verb group from the last two letters, take the stem with substr, then look up the correct ending from a table keyed by group + pronoun. This avoids many nested if checks and the single-char problem. Use getline when you want to accept full words with whitespace and print the input values while debugging to see what the program actually read.

#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

int main() {
  std::string infinitive;
  std::cout << "Infinitive (hablar): ";
  if (!std::getline(std::cin, infinitive) || infinitive.size() < 3) return 0;
  std::transform(infinitive.begin(), infinitive.end(), infinitive.begin(), ::tolower);
  std::string group = infinitive.substr(infinitive.size()-2);
  std::string stem  = infinitive.substr(0, infinitive.size()-2);

  std::unordered_map<std::string,std::unordered_map<std::string,std::string>> endings {
    {"ar", {{"yo","o"},{"tu","as"},{"el","a"},{"nosotros","amos"},{"vosotros","ais"},{"ellos","an"}}},
    {"er", {{"yo","o"},{"tu","es"},{"el","e"},{"nosotros","emos"},{"vosotros","eis"},{"ellos","en"}}},
    {"ir", {{"yo","o"},{"tu","es"},{"el","e"},{"nosotros","imos"},{"vosotros","is"},{"ellos","en"}}}
  };

  std::string pronoun; std::cout << "Pronoun (yo, tu, el, nosotros, ...): "; std::cin >> pronoun;
  std::transform(pronoun.begin(), pronoun.end(), pronoun.begin(), ::tolower);

  auto g = endings.find(group);
  if (g==endings.end() || g->second.find(pronoun)==g->second.end()) { std::cout << "Unknown input\n"; return 0; }
  std::cout << stem << g->second[pronoun] << '\n';
}

Quick troubleshooting: print the raw inputs to confirm what you read, normalize case, trim whitespace, and use "tu"/"el" (ASCII) rather than accented forms. If you want shorter code later, map pronouns to enums and use data-driven tables for irregular verbs.

Recommended Answers

All 2 Replies

1) Please wrap your code in code tags
2) Use std::string instead of char (you'll have to #include <string>) and everything should turn out much better for you :)

Dave

its you choice:string or char arrays....but using string is mostly better unless you are checking to make sure the person entered only a specific number of characters like only 2 chars rather than 3....but just go with strings and you should be fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.