..\Playground\: In function 'int main()':
..\Playground\:105:14: error: expected '}' before 'else'
}else{
^
..\Playground\: At global scope:
..\Playground\:110:1: error: expected declaration before '}' token
}
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main() {
string pw="abcdefghijklmnopqrstuvwxyz";//26
string scharacters="!@#$%^&*><!@#$%^&*><!@#$%^";//26
string ucharacters="ABCDEFGHIJKLMNOPQRSTUVWXYZ";//26
bool s=false;
bool u=false;
cout<<"How long does the password need to be? "; //First question
int len;
cin>>len;
cout<<len<<endl;
int hrb=1;
while(hrb==1){
if (len>pw.length()){
pw+=pw;
scharacters+=scharacters;
ucharacters+=ucharacters;
}else{
hrb=0;
}
}
//--------------------------------------------------------------------------
cout<<"Does it need to contain uppercase letters? "; //Second question
string up;
cin>>up;
cout<<up<<endl;
if (up=="yes" || up=="Yes" || up=="Yeah" || up=="yeah"){
pw=pw+ucharacters;
u=true;
}elseif (up=="No" || up=="no"){
u=false;
}
//--------------------------------------------------------------------------
cout<<"Does it need to contain special characters? "; //Third question
string sp;
cin>>sp;
cout<<sp<<endl;
if (sp=="yes" || sp=="Yes" || sp=="Yeah" || sp=="yeah"){
pw=pw+scharacters;
s=true;
}
elseif (sp=="No" || sp=="no"){
s=false;
//--------------------------------------------------------------------------
}
srand(time(0));
for(int x=0; x<len; x++){
int ran=0 + (rand() % len);
pw[x]=pw[ran];
pw.erase(ran,1);
}
for(int x=len; x<pw.length();x++){
pw.erase(len,30);
}
//--------------------------------------------------------------------------
bool cs=false;
if (s==true){
for(int x=0; x<=len - 1; x++){
char a=pw[x];
int y=0;
while (y<= scharacters.length()){//I had a for loop here but for some reason the for loop wasn't working so I just used a while loop instead.
if (scharacters[y]==a)
cs=true;
y=y+1;
}
}
}
//---------------------------------------------------------------------------
if (cs==0 && s==true){
srand(time(0));
int random=0 + (rand() % pw.length());
pw[random]=scharacters[random];
}
//---------------------------------------------------------------------------
bool cu=false;
if (u==true){
for(int x=0; x<=len - 1; x++){
char a=pw[x];
int y=0;
while (y<= ucharacters.length()){
if (ucharacters[y]==a)
cu=true;
y=y+1;
}
}
}
//---------------------------------------------------------------------------
int pizza=1;
while (pizza==1){
if (cu==0 && u==true){
srand(time(0) + 1);
int rando=0 + (rand() % pw.length());
for(int x=0; x>=scharacters.length(); x++){
if(rando==scharacters[x]){
int pizza=1;
}
}else{
pizza=2;
}
}
}
}
This is why I prefer Allman style indentation over K&R or its variants (https://en.wikipedia.org/wiki/Indent_style), missing/extra braces easier stand out more easily:
Your if loop that started on line 96 was not closed before an else was introduced on line 103:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
while (pizza==1)
{
if (cu==0 && u==true)
{
srand(time(0) + 1);
int rando=0 + (rand() % pw.length());
for(int x=0; x>=scharacters.length(); x++)
{
if(rando==scharacters[x])
{
int pizza=1;
}
}
}
else
{
pizza=2;
}
}
And there is a hanging closing brace on line 108, the closing brace on line 107 already encloses main().