2
Answers

C# Problem ! [Same Var]

Nicolas

Nicolas

14y
1.9k
1
Hello Guys

I'm Starting with C# and make this program to
learn more about what I'm Working on !

so..

I make a program that make questions to the user,
and the user answer them. and with this answer
the computer answer again with the answer of the user

but I get aproblem. the var of the "answer"
doesn't change with the TextBox ..

This is The code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Interatividade
{
public partial class Form1 : Form
{
List Perguntas = new List();
List Respostas = new List();
string resp = "";
int index = 0;
int index2 = 0;

public Form1()
{
InitializeComponent();



Perguntas.Add("what's your name ?");
Perguntas.Add("how are youá ?");
Perguntas.Add("How old are you ?");
button1.Text = "Start Program";
resposta.Text = "\n \n press the button below to start";
pergunta.Text = "Press the button below to start!";
pergunta.Enabled = false;
user.Enabled = false;
resposta.Enabled = false;
bt1.Enabled = false;

}

private void button1_Click(object sender, EventArgs e)
{
resposta.Text = "";
pergunta.Text = "";
button1.Text = "Go to the next...";
pergunta.Text = Perguntas[index];
user.Text = "";
button1.Enabled = false;
bt1.Enabled = true;
pergunta.Enabled = true;
user.Enabled = true;
resposta.Enabled = true;
index++;
}

private void bt1_Click(object sender, EventArgs e)
{
if (user.Text != "")
{
resp = user.Text;
Respostas.Add("hmmm " + resp + " Ok");
Respostas.Add("hmmm " + resp + " é ? OK!");
Respostas.Add("OH " + resp + " é ? hmm");
resposta.Text = Respostas[index2];
index2++;
button1.Enabled = true;
}
else
{
MessageBox.Show("Write Something", "Error 404", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}


the error is: the var "resp" doesn't change when
the questions change and the user write other thing
in the text box called "user" and press OK button
(called "bt1") I want the var resp change same
as the questions

so.. I want decisions too, example:
a question "how are you" if the user
write "Fine" the pc answer "Fine ! OK You're fine !"
or else if the user write Bad the pc answer "Why Bad man ?"


I made this only for example.. nothing serious..

but I need some help !

plz help me how I make this works ?

thx to all

and SORRY about my english.. I know this is BAD !

Hugs

Nicolas Mello


Answers (2)
Next Recommended Forum