Hey, I wrote this code that makes you type two things, then it checks if it is the same. Well, that was it was supposed to do, but then it kept saying:

expected primary-expression before "else"
expected ';' before "else"

Here's the code

#include <iostream>
#include <time.h>
#include <windows.h>
#include <string.h>
#include <conio.h>

using namespace std;

//global variables
char pass1[1000000] = {0}, pass2[1000000] = {0}, pass3[1000000] = {0};
bool checker=1;
int counter=0, thing=100;
int passCount=0;
int counter1=0;


int main(){
    cout<<"Welcome to the password checker."<<endl;
    cout<<"Please enter your new password."<<endl;
    
    while (true){
       //input
       cin>>pass1;
    
              
       cout<<"Please enter it again."<<endl;      
       
       //enter again, like in those input things   
       cin>>pass2;      
       
       while (counter1<1000000){
          if (!(pass1[passCount]==pass2[passCount])){
             thing=200;
             
          else
             ;
             }
          passCount++;
          counter1++;
       }
          
       if (thing==100)
          cout<<"Okay. Password Saved."<<endl;
          break;
          
       else if (thing==200)
          cout<<"Sorry, your two passwords are different, please type them again."<<endl;
       }

Please tell me what's wrong.

Lines 42 to 45 need { }

You should always use them, even in the places where they're considered optional. It takes almost no effort to add them (none at all for intelligent IDE's), but the amount of bug hunting they cause by omission can be huge.

This is assuming the error is coming from lines 32-37.

Your else statement is inside your if statement's braces. The error is produced by the IDE thinking there's no if statement before the else statement. It should look like the following:

if(check){
     // Do something.
}
else{
     // Do something else.
}

Also, an empty else statement serves no purpose that I know of. If you're not planning on doing any other functionality if the if statement doesn't execute, you don't need that else.

Hey, I wrote this code that makes you type two things, then it checks if it is the same. Well, that was it was supposed to do, but then it kept saying:

expected primary-expression before "else"
expected ';' before "else"

Here's the code

#include <iostream>
#include <time.h>
#include <windows.h>
#include <string.h>
#include <conio.h>

using namespace std;

//global variables
char pass1[1000000] = {0}, pass2[1000000] = {0}, pass3[1000000] = {0};
bool checker=1;
int counter=0, thing=100;
int passCount=0;
int counter1=0;


int main(){
    cout<<"Welcome to the password checker."<<endl;
    cout<<"Please enter your new password."<<endl;
    
    while (true){
       //input
       cin>>pass1;
    
              
       cout<<"Please enter it again."<<endl;      
       
       //enter again, like in those input things   
       cin>>pass2;      
       
       while (counter1<1000000){
          if (!(pass1[passCount]==pass2[passCount])){
             thing=200;
             
          else
             ;
             }
          passCount++;
          counter1++;
       }
          
       if (thing==100)
          cout<<"Okay. Password Saved."<<endl;
          break;
          
       else if (thing==200)
          cout<<"Sorry, your two passwords are different, please type them again."<<endl;
       }

Please tell me what's wrong.

#include <iostream>
#include <time.h>
#include <windows.h>
#include <string.h>
#include <conio.h>
 
using namespace std;
 
//global variables
char pass1[1000000] = {0}, pass2[1000000] = {0}, pass3[1000000] = {0};
bool checker=1;
int counter=0, thing=100;
int passCount=0;
int counter1=0;
 
 
int main(){
    cout<<"Welcome to the password checker."<<endl;
    cout<<"Please enter your new password."<<endl;
 
    while (true){
       //input
       cin>>pass1;
 
 
       cout<<"Please enter it again."<<endl;      
 
       //enter again, like in those input things   
       cin>>pass2;      
 
       while (counter1<1000000)
       {
          if (!(pass1[passCount]==pass2[passCount]))
          
             thing=200;
 
          else;
             
          passCount++;
          counter1++;
       }
 
       if (thing==100)
          {cout<<"Okay. Password Saved."<<endl;
          break;
}
       else if (thing==200)
          cout<<"Sorry, your two passwords are different, please type them again."<<endl;
       }
       cout<<pass2;
  system("PAUSE");
    return EXIT_SUCCESS;

}
commented: giving the code without any explanation is not going to help this poster. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.