Why My Program Always Crashing On Else ?

#include<stdio.h>
using namespace std;
#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<process.h>
#include<stdlib.h>
int main()

{
string userchoice;
string userchoicepass;
string userchoicenum;
string userchoiceyes;
bool result = false;



system("color 85");
cout << "Write your username" <<endl;
cin >> userchoice;

if(userchoice == "admin")
getch();
cout<<"Write Your Password" <<endl;



else{
cout << "Invalid Input"<<endl;
getch();
exit(0);
}




cin >> userchoicepass;
if(userchoicepass == "qwert123")
cout << "Correct" <<endl;

else{
cout<<"Invalid Input"<<endl;
getch();
exit(0);
}
if(userchoicepass == "qwert123")
cout <<"Write Your Securty Code" <<endl;


cin >> userchoicenum;

if(userchoicenum == "iamreal" )
getch();
cout << "Correct" <<endl;







if(userchoicenum == "iamreal")
cout << "Prove" <<endl;



cin >> userchoiceyes;

if(userchoiceyes == "iamreallyreal")
getch();
cout << "Welcome my friend :D" <<endl;


return 0;



}
It seems there are missing braces { } around the statements to be controlled by the if statements.

The first one,
1
2
if(userchoice == "admin")
    getch();
only the single statement getch(); is controlled by the if, that control block ends there. Later there is an else, but because there is no corresponding if, it is unmatched.

With the braces added, it would look like this:
1
2
3
4
5
6
7
8
9
10
11
    if (userchoice == "admin")
    {
        getch();
        cout << "Write Your Password" << endl;
    }   
    else
    {
         cout << "Invalid Input"<<endl;
         getch();
         exit(0);
    }
Topic archived. No new replies allowed.