Question Mismatched Brace

n72.75

Move slow and try not to break too much.
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,696
Reaction score
1,353
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
somewhere within this piece of code, I have an extra or missing brace. I've been staring at it for the past 3 hours but I cant find it. Do any of you see it?

Code:
#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
	char redVblue;
	char greenVyellow;
	char orgageVpurple;
	long long twodigitnum = 0;
	unsigned long long idnumber = 0;
	char programer;
	char fortranVc;
	char dosVunix;
	char maleVfemale;
	char BeforeJune;
	char BeforeApril;
	char BeforeAugust;
	short shoesize = 0;
	char ownCar;
	unsigned long licenseplate = 0;
	char introvertVextrovert;
	char visualLearner;
	unsigned long long length = 0;
	char variance = 1;
	char value = 0;
	unsigned long long seed = 0;
	


	std::cout << "\n\nMATTHEW HUME PASSWORD GENERATOR\n\n\n";
	std::cout << "This program will generate a unique password based\ninput from the user. If you forget your password,\njust reanswer each question the same way you did\nthe first time, and the program will generate the\nsame password again.\n\n******************************************************************\n";
	std::cout << "The following part of the program will ask you about colors:\n\n";

/**************************************************************************************************************************************/
	while(true)
	{
		std::cout << "Would you say that you prefer the color red over the color blue(y/n): ";
		std::cin >> redVblue;
		if(redVblue == 'n' || redVblue == 'N' || redVblue == 'y' || redVblue == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		{
	}

/**************************************************************************************************************************************/
	
	while(true)
	{
		std::cout << "Would you say that you prefer the color green over the color yellow(y/n): ";
		std::cin >> greenVyellow;
		if(greenVyellow == 'n' || greenVyellow == 'N' || greenVyellow == 'y' || greenVyellow == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}

/**************************************************************************************************************************************/
	while(true)
	{	
		std::cout << "Would you say that you prefer the color orange over the color purple(y/n): "; 
		std::cin >> orgageVpurple;
		if(orgageVpurple == 'n' || orgageVpurple == 'N' || orgageVpurple == 'y' || orgageVpurple == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	std::cout << "\n\n******************************************************************\nThe following part of the program will ask you about numbers:\n\n";
	std::cout << "Please enter your favorite number: ";
	std::cin >> twodigitnum; // realisticly could be any number
/**************************************************************************************************************************************/	
	std::cout << "Please enter an ID number such as your SSN or equivalent: ";
	std::cin >> idnumber;
/**************************************************************************************************************************************/
	while(true)
	{	
		std::cout << "\n\n******************************************************************\nThe following part of the program will ask you about programing:\n\n";
		std::cout << "Are you a programer(y/n): ";
		std::cin >> programer;
		if(programer == 'n' || programer == 'N' || programer == 'y' || programer == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	if(programer == 'y' || programer == 'Y')
	{
		while(true)
		{
			std::cout << "Would you say that you prefer FORTRAN over C(y/n): ";
			std::cin >> fortranVc;
			if(fortranVc == 'n' || fortranVc == 'N' || fortranVc == 'y' || fortranVc == 'Y')
			{
				break;
			}
			else
			{
				std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
			}
		}
		
		while(true)
		{
			std::cout << "Would you say that you prefer DOS over UNIX(y/n): ";
			std::cin >> dosVunix;
			if(dosVunix == 'n' || dosVunix == 'N' || dosVunix == 'y' || dosVunix == 'Y')
			{
				break;
			}
			else
			{
				std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
			}
		}
	}
	else
	{
		fortranVc = 'n';
		dosVunix = 'n';
	}
/**************************************************************************************************************************************/	
	while(true)
	{
		std::cout << "\n\n******************************************************************\nThe following part of the program will ask you about your self:\n\n";
		std::cout << "Are you male or female(m/f): ";
		std::cin >> maleVfemale;
		if(maleVfemale == 'm' || maleVfemale == 'M' || maleVfemale == 'f' || maleVfemale == 'F')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	while(true)
	{	
		std::cout << "Is your birthday before June 1st(y/n): ";
		std::cin >>BeforeJune;
		if(BeforeJune == 'y' || BeforeJune == 'Y' || BeforeJune == 'n' || BeforeJune == 'N')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/	
	if(BeforeJune == 'y' || BeforeJune == 'Y')
	{
		while(true)
		{
			std::cout << "Is your birthday before April 1st(y/n): ";
			std::cin >> BeforeApril;
			BeforeAugust = false;
			if(BeforeApril == 'n' || BeforeApril == 'N' || BeforeApril == 'y' || BeforeApril == 'Y')
			{
				break;
			}
			else
			{
				std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
			}
		}
	}
	else
	{
		while(true)
		{
			std::cout << "Is your birthday before August 1st(y/n): ";
			std::cin >> BeforeAugust;
			BeforeApril = false;
			if(BeforeAugust == 'n' || BeforeAugust == 'N' || BeforeAugust == 'y' || BeforeAugust == 'Y')
			{
				break;
			}
			else
			{
				std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
			}
		}
	}
	
	std::cout << "What is your shoe size: ";
	std::cin >> shoesize;
/**************************************************************************************************************************************/
	while(true)
	{			
		std::cout << "Do you own a car(y/n):";
		std::cin >> ownCar;
		if(ownCar == 'n' || ownCar == 'N' || ownCar == 'y' || ownCar == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	if(ownCar == 'y' || ownCar == 'Y')
	{
		std::cout << "Enter the NUMBERS on your license plate IN ORDER WITH NO SPACES: ";
		std::cin>>licenseplate;
	}
	else
	{
		licenseplate = 8675309;
	}
/**************************************************************************************************************************************/
	while(true)
	{
		std::cout << "Are you an introvert or an extrovert(i/e):";
		std::cin >> introvertVextrovert;
		if(introvertVextrovert == 'i' || introvertVextrovert == 'I' || introvertVextrovert == 'e' || introvertVextrovert == 'E')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	while(true)
	{	
		std::cout << "Are you a visual learner(y/n): ";
		std::cin >> visualLearner;
		if(visualLearner == 'n' || visualLearner == 'N' || visualLearner == 'y' || visualLearner == 'Y')
		{
			break;
		}
		else
		{
			std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
		}
	}
/**************************************************************************************************************************************/
	std::cout << "\n\n******************************************************************\nThe following part of the program will ask you about your password:\n\n";
	std::cout << "How long would you like your password to be: ";
	std::cin >> length;
	std::cout << "\n\n******************************************************************\nYour password is being generated...\n\n";
	char *password = new char[length];
	if(*password = NULL)
	{
		return 1;
	}
/**************************************************************************************************************************************/
		seed = ((twodigitnum*idnumber*shoesize*licenseplate+324134)%length)*127;	
		if(redVblue == 'n' || redVblue == 'N')
		{
			variance += 116;
		}
		else
		{
			variance += 35;
		}
/**************************************************/
		if(greenVyellow == 'y' || greenVyellow == 'Y')
		{
			variance += 105;	
		}
		else
		{
			variance += 83;
		}
/**************************************************/
		if(orgageVpurple == 'n' || orgageVpurple == 'N')
		{
			variance += -27;
		}
		else
		{
			variance += 30;
		}
/**************************************************/
		if(programer == 'y' || programer == 'Y')
		{
			variance += 52;
		}
		else
		{
			variance += -4;
		}
/**************************************************/
		if(fortranVc == 'n' || fortranVc == 'N')
		{
			variance += -119;
		}
		else
		{
			variance += -26;
		}
//**************************************************
		if(dosVunix == 'n' || dosVunix == 'N')
		{
			variance += 48;
		}
		else
		{
			variance += 105;
		}
//**************************************************
		if(maleVfemale == 'n' || maleVfemale == 'N')
		{
			variance += -28;
		}
		else
		{
			variance += 98;
		}
//**************************************************
		if(BeforeJune == 'y' || BeforeJune == 'Y')
		{
			variance += -70;
		}
		else
		{
			variance += 125;
		}
//**************************************************
		if(BeforeApril == 'n' || BeforeApril == 'N')
		{
			variance += 94;
		}
		else
		{
			variance += -68;
		}
//**************************************************
		if(BeforeAugust == 'y' || BeforeAugust == 'Y')
		{
			variance += 126;
		}
		else
		{
			variance += 71;
		}
//**************************************************
		if(ownCar == 'n' || ownCar == 'N')
		{
			variance += -103;
		}
		else
		{
			variance += -18;
		}
//**************************************************
		if(introvertVextrovert == 'y' || introvertVextrovert == 'Y')
		{
			variance += -104;
		}
		else
		{
			variance += -124;
		}
//**************************************************
		if(visualLearner == 'n' || visualLearner == 'N')
		{
			variance += 102;
		}
		else
		{
			variance += -3;
		}
//**************************************************
		for(int i = 0; i < (length+1);i++)
		{
			value = 0;		
			value = ((seed*variance)%125);
			if(value < 33)
			{
				password[i] = value + 33;
			}
			else if(value > 125)
			{
			password[i] = value - 26;
			}
			else
			{
				password[i] = value;
			}
		}
//**************************************************
	password[length+1] = 0;
	std::cout << "YOUR PASSWORD IS:  ";
	for(int i = 0; i < (length);i++)
	{
		std::cout << password[i];
	}
	std::cout << "\n\n\n\n";

	delete[] password;
	return 0;
}
 

Linguofreak

Well-known member
Joined
May 10, 2008
Messages
5,034
Reaction score
1,273
Points
188
Location
Dallas, TX
Line 46 perhaps?

If I'm right, it's probably not so much *missing* as *flipped*.

Code:
        while(true)
        {
     <SNIP>
                else
                {
                        std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
               [COLOR="Red"] {[/COLOR]
        }
 

fireballs619

Occam's Taser
Donator
Joined
Nov 4, 2009
Messages
788
Reaction score
4
Points
33
Well, by my count, there are 79 '{' braces, and only 77'}' braces. If Linguo's solution is true, that brings my count to 80 and 76. I don't know much about coding outside of Python, but does every open brace have to have a closed brace? If so, you are missing 4 close braces, or have two open braces were there should be closed ones. Not much of a help, I know.
 

fireballs619

Occam's Taser
Donator
Joined
Nov 4, 2009
Messages
788
Reaction score
4
Points
33
Flip the open brace and the count goes to 78-78.

I could just be failing to think here, but if there was a } brace in the place of the new { brace, doesn't that make there one more { brace and one less }, hence the 80-76. I was never good at picturing this stuff:lol:.
 

n72.75

Move slow and try not to break too much.
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,696
Reaction score
1,353
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
Line 46 perhaps?

If I'm right, it's probably not so much *missing* as *flipped*.

Code:
        while(true)
        {
     <SNIP>
                else
                {
                        std::cout << "\nERROR: INVALID INPUT, PLEASE TRY AGAIN\n";
               [COLOR="Red"] {[/COLOR]
        }


That was it, thanks!

Now it's on to fixing the segfaults and some optimization...
 

Linguofreak

Well-known member
Joined
May 10, 2008
Messages
5,034
Reaction score
1,273
Points
188
Location
Dallas, TX
I could just be failing to think here, but if there was a } brace in the place of the new { brace, doesn't that make there one more { brace and one less }, hence the 80-76. I was never good at picturing this stuff:lol:.

No, that's what would happen if you flipped a } into a {.

Here we're flipping a { into a }.
 

fireballs619

Occam's Taser
Donator
Joined
Nov 4, 2009
Messages
788
Reaction score
4
Points
33
Ack! Too many braces:lol:

I see it now though. This is why I keep my mouth shut when it comes to coding.
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Do you type your code in notepad or some decent IDE with highlighting? Syntax/brace highlighting/matching makes things a lot easier. Using the VC++ 2008 express edition IDE it took like 10 seconds to track the brace error. All I had to do was to erase/retype the last brace, and that highlighted the matching brace, ie. the one that was inverted.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,617
Reaction score
2,337
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
You should fix this typical error as well:

Code:
if(*password = NULL)

This always sets password to null (assignment), makes the if go into the else case (since it evaluates to 0 or logical false), the equality comparison operator is "==".
 
Top