Advertisement

Little Problem with my code

Started by November 30, 2000 02:43 PM
2 comments, last by reaptide 24 years, 1 month ago
Hello everyone, I'm having a problem with the snippet of code below. The program goes into an infinite loop when entering the while loop, and I can't figure out why. The code is part of a small console app I'm working on, and windows.h has been include so that the LPSTR variables work.
  

int MapEditor(void)
{
	int MapArray[XMAPSIZE][YMAPSIZE];	// Store the map's values

	int XValue = 0;						// Temporary X Value

	int YValue = 0;						// Temporary Y Value

	int InputValue = 0;					// Temporary Input Value

	LPSTR Filename = 0;					// Filename of the map

	LPSTR Quit = "n";					// Should we quit


	cout << "Enter the Filename: ";
	cin >> Filename;

	while (Quit != "y" || "Y")
	{
		cout << endl << endl << "Enter the X coordinate: ";
		cin >> XValue;

		cout << endl << endl << "Enter the Y coordinate: ";
		cin >> YValue;

		cout << endl << endl << "Enter the value: ";
		cin >> InputValue;

		MapArray[XValue][YValue] = InputValue;

		cout << endl << endl << "Do you wish to quit(Y/N): ";
		cin >> Quit;
	}

	cout << endl << endl << "Saving File...";
	
	ReadWriteMap(Filename, MapArray, true);

	cout << endl << endl << "-File Saved-";

	return(1);
}

  
Anyone got an idea what's going on. Thanks, Derek Edited by - Reaptide on 11/30/00 2:45:42 PM
Try to change the while () to
  while (Quit != "y" && Quit != "Y")   

Take a minute to think about it.

Edited by - VolkerG on November 30, 2000 3:51:27 PM
Advertisement
I think i figured it out:

This: while (Quit != "y" || "Y")
Should be: while (Quit != "y" && Quit!="Y")
Don't use LPSTR's for your data. use:
    char Filename[256]; // Use array of char'schar Quit = 'n';    // One char, no need for more// Change the *while* code to thiswhile (Quit == 'n'){   // code...}    


Worked for me.

Edited by - jt_845s on November 30, 2000 4:03:06 PM
[source]#define ignite_software 1[/source]

This topic is closed to new replies.

Advertisement