Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help! ( Yes i am noob o.0 )
#1
Hey guys i just tried to code a "very simple login system"
But when i try to compile it says that the last } is a error.
If you don't understand my error then look at this picture:
Screenshot (Click to View)
here is my code:
Code:
#include <iostream>
#include <windows.h>
#include <winable.h>

using namespace std;

int main(void)
{
    string username;
    cout << "Enter your username:  ";
    getline (cin, username);
    if(username == "Rand0m")
{
    string password;
    cout << "Enter your password to access the program:  ";
    if(password == "iamcool")

    {
                string answer;
                system("CLS");
                cout << "Welcome back dude!";
                Sleep(2000);
                cout << "\nHow have you been?\n";
                getline (cin, answer);
                
                if(answer == "bad")
                {
                          cout << "Sorry to hear that.";
                          }
                                  system("PAUSE>nul");
}
Reply
#2
You are missing 2 or 3 closing brackets.
Here you have the clean code, I think that would do it.

Code:
#include <iostream>
#include <windows.h>
#include <winable.h>

using namespace std;

int main(void)
{
    string username;
    cout << "Enter your username:  ";
    getline (cin, username);
    if(username == "Rand0m")
    {
        string password;
        cout << "Enter your password to access the program:  ";
        if(password == "iamcool")
        {
            string answer;
            system("CLS");
            cout << "Welcome back dude!";
            Sleep(2000);
            cout << "\nHow have you been?\n";
            getline (cin, answer);
                    
            if(answer == "bad")
            {
                cout << "Sorry to hear that.";
            }
        }
    }
    system("PAUSE>nul");
}

Few tips, instead of system("PAUSE"), use cin.get().
And instead of putting if's into if's try using if, else, else if or even switch.

Also, if I may suggest, use Code::Blocks
http://www.codeblocks.org/
Reply
#3
As Gaijin said you are missing two closing brackets.
[Image: burninglove4.png]
Reply
#4
Thanks alot it is working now Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)