[Solved] C++ error at the last line of code


The code that works is here

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int number_normal;
int number_hard;
int guess_normal;
int guess_hard;
int tries_normal=0;
int tries_hard=0;
int mode;
int main()
{


    {
        cout<<"Choose your mode..."<<endl;
        cout<<"Normal (Press 1) or Hard (Press 2)"<<endl;
        cin>>mode;
        if(mode=1)
            cout<<"Normal mode chosen."<<endl;
                goto normal;
                if(mode=2)
                cout<<"Hard mode chosen!"<<endl;
                goto hard;
                return 0;
    }
{

    hard:

        cout<<"I chose a random number in a range from 1 to 100, can you      guess it?"<<endl;
        srand(time(NULL));
        number_hard = rand()%100+1;

    while(guess_hard!=number_hard)
        {
        tries_hard++;
        cout<<"Enter your guess!(Try "<<tries_hard<<"): ";
        cin>>guess_hard;

        if(guess_hard==number_normal)
            cout<<"Respect! You guessed it in "<<tries_hard<<" tries!"<<endl;
        }
}
{

    normal:

        cout<<"I chose a random number from 1 to 100. I will give you some clues! Try to guess it."<<endl;
        srand(time(NULL));
        number_normal = rand()%100+1;

    while(guess_normal!=number_normal)
        {
        tries_normal++;
        cout<<"Enter your guess!(Try "<<tries_normal<<"): ";
        cin>>guess_normal;

        if(guess_normal==number_normal)
            cout<<"Congrats! You're lucky. (Won in "<<tries_normal<<" tries!)"<<endl;

        if(guess_normal<number_normal)
            cout<<"Too low."<<endl;
        else if(guess_normal>number_normal)
            cout<<"That's too much!"<<endl;

        //system("pause");
    }
}
    return 0;
}

Well, you didn’t used braces across your while loops, and as @cowls suggested, there was a closing brace missing after main. Everything else was fine. Also you used a = for comparison between to variables, instead of ==, = is a assignment operator, while == is used for comparison.

0

solved C++ error at the last line of code