Hi, it's me again with another question. Here is the thing. I have a small game - a picture is shown and you should type the name of the person that's on the picture. Then you have a "check" button which when clicked checks if the answer is correct or incorrect.But i got a problem, it always checks for the latest command given by me, for example - if...==Jimi-correct, and i want to get it changing, like checking for each picture's name. My first picture is Philip, and it expects me to write Jimi, to answer "Correct", which is my second picture's name. Here is the code. Thank you.

#pragma endregion
	private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 textBox1->Clear();
				 label1->Visible=false;
				 label3->Visible=true;
				 label2->Text="";
			 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 				 if (textBox1->Text=="Filip")
				 {
					 label2->Text="Correct";
				 }
							 else
							 {
								 label2->Text="Incorrect";
							 }
				 
				 if (textBox1->Text=="Jimi")
				 {
					 label2->Text="Correct";
				 }
				 else
				 {
					label2->Text="Incorrect";
				 }
	
		 }
};
}

1. Please, correct code indentation before send the code next time.
2. Your program performs two absolutely identical actions for Filip and Jimi cases. Why?

Because that's what I like to do, if the name is guessed-correct, otherwise - incorrect. And the first-shown picture changes to the second picture. How can i check for every next picture if the correct name is entered?

Here is my improved code, I added more buttons and now each picture has it's own button, it works now, but i still don't know how to do it with one button only. Maybe this code will help somebody, so take a lok at it.

#pragma endregion
	private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 textBox1->Clear();
				 label1->Visible=false;
				 label3->Visible=true;
				 label2->Text="";
				 //label3->Visible=false;
				 //label4->Visible=true;
				 //label2->Text="";
				 button1->Visible=false;
				 button4->Visible=true;
			 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label3->Visible==false && label1->Visible==true  && textBox1->Text=="Filip")
				 {
					 label2->Text="Correct";
				 }
							 else
							 {
								 label2->Text="Incorrect";
							 }
			 button2->Visible=false;
			 button5->Visible=true;

			 
							 
				 
			 
	
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 label1->Visible=true;
		 }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			 label3->Visible=false;
			 label4->Visible=true;
			 label2->Text="";
			 textBox1->Clear();
		 }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label3->Visible==true && textBox1->Text=="Jimi")
				 {
					 label2->Text="Correct";
				 }
				 else
				 {
					label2->Text="Incorrect";
				 }
			 /*if (label1->Visible==false && label3->Visible==false && label4->Visible==true && textBox1->Text=="Goce")
			 {
				 label2->Text="Correct";

			 }
			 else
			 {
				 label2->Text="Incorrect";
			 }*/
		 }
};
}

What I'd recommend that might work is, if you look back at the previous code, instead of switching to a million different buttons and textboxes, use System::Strings instead. So, instead of saying 'if( textbox1->Text == "Jimi" ) etc, you should declare one System::String, Just above the "pragma region Windows Form Designer Generated code" line (near the top of the file). So you'd type this in:

String^ currentName;

Now, instead of using this:

#pragma endregion	private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {			 
}	

private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) { 			 
}	

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {	 textBox1->Clear();
                 label1->Visible=false;		
	 label3->Visible=true;	
	 label2->Text="";
}

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {	 if (textBox1->Text=="Filip")
	 {
	      label2->Text="Correct";	
	 }			
	 else
	 {								     label2->Text="Incorrect";
	 } 

                 if (textBox1->Text=="Jimi")		
	 {		
	       label2->Text="Correct";
	 }	
	 else
	 {
	label2->Text="Incorrect";
	 }
             }
      }
;}
#pragma endregion

Try using this (Don't forget that 'String^ currentName' should be declared):

#pragma endregion	private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {			 
}	

private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) { 			 
}	

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {	 textBox1->Clear();
                 label1->Visible=false;		
	 label3->Visible=true;	
	 label2->Text="";
}

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
//set currentName to "Filip" to begin with.
                 currentName = "Filip";
	 if (textBox1->Text == currentName)
	 {
                       //if it's corrent, set currentName to "Jimi" and move on to the next level
	      label2->Text="Correct";
	      currentName = "Jimi";
	 }			
	 else
	 {								     label2->Text="Incorrect, try again";
	 } 

  if (textBox1->Text=="Jimi")		
	 {		
                       //set currentName to "Sam"... see where this is going?
                       currentName = "Sam";
	       label2->Text="Correct";
	 }	
	 else
	 {
	label2->Text="Incorrect, try again";
	 }
             }
      }
;}
#pragma endregion

See? You just need to use a System::String (make sure you don't use any other types, such as an std::string, cause textboxes use System ones), and keep repeating ifs as many times as you like. This should work with Visual C++, but I'm not positive. Let me know if it does, good luck :)

Well, I decided to replace the textboxes with radiobuttons, so I'm fine now, but thanks a lot, this helped me very much in planning my future projects ! You people rock :) Not everyone would do this - helping everyone without taking advantage of it. By the way, may I ask whether someone speaks Macedonian language in here ? Thanks again.

Glad I could help.

And sry, I don't speak macedonian :)

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.