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
NicolasPosted Dec 2, 2009, 5:53 PM
I Try this before you answer, and I get that !
but.. Now. I have a problem with the "decisions" of the second question ("How Are You"
This is the Code:
switch (index2)
{
case 0:
if (resp == "nicolas" || resp == "admin" || resp == "Nicolas" || resp == "Nícolas" || resp == "nícolas" || resp == "nick")
{
Respostas.Add("THE BEST JOKE!");
MessageBox.Show("Hm... \n\n trying to use my name ? ? \n\n HAHA\n\n I'll Close this\n\n Bye Bye ***** !", "Joke", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
Respostas.Add("Hello " + resp + " Welcome to this questions");
}
break;
case 1:
if (Convert.ToString(resp) == "fine" || Convert.ToString(resp) == "Fine")
{
Respostas.Add("Very Good");
}
else if (Convert.ToString(resp) == "Bad" || Convert.ToString(resp) == "bad")
{
Respostas.Add("Ahh Very Bad");
}
else if (resp != "Fine" || resp != "fine" || resp != "Bad" || resp != "bad")
{
MessageBox.Show("Write Only 'Bad' ou 'Fine'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
resp = user.Text;
}
break;
case 2:
if (Convert.ToInt32(resp) < 18 && Convert.ToInt32(resp) >=1)
{
Respostas.Add("Ah " + resp + " IEIEIE");
}
else if (Convert.ToInt32(resp) >= 18 && Convert.ToInt32(resp) <= 100)
{
Respostas.Add("Ah " + resp + " IEIEIE");
}
else if (Convert.ToInt32(resp) > 100)
{
Respostas.Add("Ah " + resp + " OMG YOURE DEAD");
}
else
{
Respostas.Add("Ah " + resp + " OMG how you talking ?");
}
break;
}
}
else
{
MessageBox.Show("Write something,"Erro 404", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
resposta.Text = Respostas[index2];
index2++;
button1.Enabled = true;
}
catch (Exception ee)
{
MessageBox.Show("Ultra ERROR \n " + ee + "", "OMG", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
}
so In the line of case 1: the question is "How Are You" if the user write Fine. this will go to the answer of the fine, if the user write Bad this will go to the answer for the Bad but If the user don't write Bad or Fine. He will asked again of the same question.
I want a loop, while, for, do while, or something about this for Repeat the question ultin the user write Bad or Fine
Do you can help me to do this ?
Thx for All !
Amit ChoudharyPosted Dec 1, 2009, 11:51 PM
If this is your code then the response will not change cause you have created only one case of response you have to put some keywords and other sentences then after matching with them you can send the different response.
Here in your code i can see only a single response is send back to the user....
so there's no coding error you have to write some logic about it.... like you can use "switch case" for different cases...my bests with you
hope this helps you, and don't forget to mark the answer cause it takes time to give a right response.... :)