C++ A function definition is not allowed here before { token

Programovacie jazyky, rady, poradňa...
Jacobs322
Light Star
Light Star
Používateľov profilový obrázok
Príspevky: 232
Registrovaný: 25 máj 2013, 12:10

C++ A function definition is not allowed here before { token

Príspevok od používateľa Jacobs322 »

Zdravím. Toto sú časti kódu v ktorom mi to vypisuje error "a function definition is not allowed here before { token". Neviem prečo.

Kód: Vybrať všetko

int main()
{
    srand(time(0));

    Intro();
    FirstChoice();
    ChangeInfo();
    cout << "So let's start. Here is the first Stock Market List. Your starting capital is 10 000 dollars. Your goal is 300 000 dollars. It's easy ! \n";
    cout << "You will move in weeks. Every 4 weeks you will get list of world's stock market status. Good luck, " << FullName << endl;

    StockMarketList();
    cout << "Here is your first " << building << ". In the time, you will buy more " << building << "s." << endl;

    BasicGameCycle();

    return 0;
}

Kód: Vybrať všetko

void Intro()
{
    double version = 0.1;
    cout << "version " << version << endl << endl;

    cout << "Welcome to Stock Market Simulator (SMS). Please enjoy. \n" << endl;

    cout << "What is your name ? \n";
    getline(cin,FullName);

    cout << "And your age is ? \n";
    cin >> Age;

}
a ešte

Kód: Vybrať všetko

void FirstChoice()
{

    cout << "Welcome to SMS " << FullName << endl;
    cout << "First you have to choose commodity you wanna trade with. Minerals = easy ----- Fruits = hard \n";
    cout << "Minerals : Iron, Copper, Gold, Tin \n";
    cout << "Fruits : Apples, Bananas, Lemons \n";
    cin >> com;

    while(com != "Iron" && com != "Copper" && com != "Gold" && com != "Tin" && com != "Apples" && com != "Bananas" && com != "Lemons")
    {
        cout << "Please, choose from the list. \n";
        cin >> com;
    }


    cout << "Hmm " << com << " is great choice ! \n";

    if (com == "Apples" || com == "Bananas" || com == "Lemons")
    {
        building = "plantage";
    }else{
        building = "mine";
    }


}
Išlo to v pohode kúsok kódu som zmenil - ani nie v týchto funkciách a zrazu toto...
pcsiete
Medium Star
Medium Star
Príspevky: 413
Registrovaný: 07 dec 2012, 18:47

Re: A function definition is not allowed here before { token

Príspevok od používateľa pcsiete »

Takúto chybu dostaneš väčšinou keď definuješ funkciu v inej funkcii. Ak to nerobíš, skontroluj si všade množinové zátvorky a bodkočiarky (aj v headeroch).
Jacobs322
Light Star
Light Star
Používateľov profilový obrázok
Príspevky: 232
Registrovaný: 25 máj 2013, 12:10

Re: C++ A function definition is not allowed here before { t

Príspevok od používateľa Jacobs322 »

Tú prvú možnosť som vylúčil, ostáva tá druha ktorú su povedal no v tej funckii int main je všetko v poriadku, nechápem prečo tak zrazu to vyhodilo chybu.
lowmanek
Light Professional
Light Professional
Používateľov profilový obrázok
Príspevky: 977
Registrovaný: 04 apr 2010, 8:53
Bydlisko: 221B Baker Street

Re: C++ A function definition is not allowed here before { t

Príspevok od používateľa lowmanek »

To čo si sem postol nevyzerá na chybu...pošli celý kód ;)
A predtým ako ho pošleš spočítaj { a }. Možno ho potom ani nebudeš musieť posielať :D
Jacobs322
Light Star
Light Star
Používateľov profilový obrázok
Príspevky: 232
Registrovaný: 25 máj 2013, 12:10

Re: C++ A function definition is not allowed here before { t

Príspevok od používateľa Jacobs322 »

Dakujem, bola chyba v pocte { a } :D
Napísať odpoveď