Expected declaration before "}" token

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int i = 5;
    double balance = 0;
    string username;
    string password;
    string enter_password;
    string deposit;
    string withdraw;
    string dw_answer;
    double d_answer;
    double w_answer;
    deposit = "How much do you wish to deposit? ";
    withdraw = "How much do you wish to withdraw? ";
    cout << "Enter your username: ";
    cin >> username;
    if (username == "Matteo") {
        cout << "Username recognized." << endl << "Please enter password: ";
        password = "boyinaband";
        cin >> enter_password;
        if (enter_password == password) {
            cout << "You have logged in. Welcome back, Matteo." << endl;
            cout << "Your current balance is " << balance << "." << endl;
            while (i == 5) { 
            cout << "Would you like to deposit or withdraw? ";
            cin >> dw_answer;
            if (dw_answer == "deposit" || dw_answer == "Deposit") {
                cout << deposit;
                cin >> d_answer;
                balance = balance + d_answer;
                cout << "Your balance is now " << balance << "." << endl;
            }
            else if (dw_answer == "withdraw" || dw_answer == "Withdraw") {
                try {
                    if (balance == 0) {
                        throw 99;
                    }
                }
                catch (int x) {
                    cout << "Error " << x << " - Cannot withdraw.";
                }
            }
                else {
                        cout << withdraw;
                        cin >> w_answer;
                        balance = balance - w_answer;
                }
                }
                
            }
            }
        }
        }
    return 0;
}

This code gives me the error of "Expected declaration before “}” token. Anybody knows why?

The compiler knows why.

Are you lost?

If you Auto format your code in the IDE you will see this at the end of the main() function

        else
        {
          cout << withdraw;
          cin >> w_answer;
          balance = balance - w_answer;
        }
      }
    }
  }
}
}
return 0;
}

It seems that you have mismatched pairs of { and } in the code

Which Arduino board are you using ?

justaboi:

#include <iostream>

#include
using namespace std;

int main()
{
   int i = 5;
   double balance = 0;
   string username;
   string password;
   string enter_password;
   string deposit;
   string withdraw;
   string dw_answer;
   double d_answer;
   double w_answer;
   deposit = "How much do you wish to deposit? ";
   withdraw = "How much do you wish to withdraw? ";
   cout << "Enter your username: ";
   cin >> username;
   if (username == “Matteo”) {
       cout << “Username recognized.” << endl << "Please enter password: ";
       password = “boyinaband”;
       cin >> enter_password;
       if (enter_password == password) {
           cout << “You have logged in. Welcome back, Matteo.” << endl;
           cout << "Your current balance is " << balance << “.” << endl;
           while (i == 5) {
           cout << "Would you like to deposit or withdraw? ";
           cin >> dw_answer;
           if (dw_answer == “deposit” || dw_answer == “Deposit”) {
               cout << deposit;
               cin >> d_answer;
               balance = balance + d_answer;
               cout << "Your balance is now " << balance << “.” << endl;
           }
           else if (dw_answer == “withdraw” || dw_answer == “Withdraw”) {
               try {
                   if (balance == 0) {
                       throw 99;
                   }
               }
               catch (int x) {
                   cout << “Error " << x << " - Cannot withdraw.”;
               }
           }
               else {
                       cout << withdraw;
                       cin >> w_answer;
                       balance = balance - w_answer;
               }
               }
               
           }
           }
       }
       }
   return 0;
}




This code gives me the error of **"Expected declaration before "}" token.** Anybody knows why?

See reply #2