Need help with coding

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
0
Location
London
XP
815
Country
I'm doing a C sharp homework which is due tomorrow and I can't seem to get things right. Please help!

CODE
private void button1_Click(object sender, EventArgs e)
{
string userInput;
userInput = this.textBox1.Text;

if (userInput.Contains("$"))
{
this.lblOutput.Text = "Thank you";
this.lblOutput.ForeColor = Color.Green;
}
else
{
this.lblOutput.Text = "Error";
this.lblOutput.ForeColor = Color.Red;
}
}



This code is embedded in a button in the form I made. This code means that if "$" is entered in the text box when the button is pressed, it will display the message "Thank You". Otherwise, it will say "Error".

Now what I need to do is to change the code so "Thank You" will be displayed when a character between 0-9 is entered. Can anyone help me?

I would appreciate the help! Also, if you got a very reliable source for learning C# and stuff, please give them to me.
 

tj_cool

Site dev
Supervisor
Joined
Jan 7, 2009
Messages
10,064
Trophies
2
Location
This planet
XP
3,106
Country
Belgium
I know nothing of c# so perhaps this doesn't work, but I'll try anyway
tongue.gif


1) if (userInput.Contains("£") || userInput.Contains("%"))
2) if (userInput.Contains("$") && userInput.Contains("£"))
3) no idea
tongue.gif


someone else correct me please
smile.gif
 

Mangofett

GBAtemp Testing Area
Member
Joined
May 14, 2006
Messages
4,885
Trophies
1
Age
19
XP
1,060
Country
United States
Okay, I don't know C# either but here is how it would happen for #3 in Java(pseudocode):

x =scanner.nextint (this gets an integer value)
if (x>=0 && x
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
0
Location
London
XP
815
Country
tj_cool said:
I know nothing of c# so perhaps this doesn't work, but I'll try anyway
tongue.gif


1) if (userInput.Contains("£") || userInput.Contains("%"))
2) if (userInput.Contains("$") && userInput.Contains("£"))
3) no idea
tongue.gif


someone else correct me please
smile.gif

These worked. Thanks a bunch!
happy.gif


Linkiboy said:
Okay, I don't know C# either but here is how it would happen for #3 in Java(pseudocode):

x =scanner.nextint (this gets an integer value)
if (x>=0 && x
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
0
Location
London
XP
815
Country
Psyfira said:
Userinput is being pulled in as a string. You may need to convert it to a number datatype before the comparisons will work.
Converting strings to numbers
I don't get it...

I'm a complete noob in programming. I have only learned basic stuff like designing forms. Not into deep coding and stuff yet so I'm not really familiar with most of the codes.

Something tells me that I just need to do a slight change in that line I highlighted in bold to get it working but...
 

Mangofett

GBAtemp Testing Area
Member
Joined
May 14, 2006
Messages
4,885
Trophies
1
Age
19
XP
1,060
Country
United States
What I got from that page (no way to test it but it looks right)
CODEprivate void button1_Click(object sender, EventArgs e)
{
string userInput;
double tempnumber;
userInput = this.textBox1.Text;
tempnumber = Convert.ToDouble(userInput);

if ((tempnumber=0))
{
this.lblOutput.Text = "Thank you";
this.lblOutput.ForeColor = Color.Green;
}
else
{
this.lblOutput.Text = "Error";
this.lblOutput.ForeColor = Color.Red;
}
}
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
0
Location
London
XP
815
Country
Linkiboy said:
What I got from that page (no way to test it but it looks right)
CODEprivate void button1_Click(object sender, EventArgs e)
{
string userInput;
double tempnumber;
userInput = this.textBox1.Text;
tempnumber = Convert.ToDouble(userInput);

if ((tempnumber=0))
{
this.lblOutput.Text = "Thank you";
this.lblOutput.ForeColor = Color.Green;
}
else
{
this.lblOutput.Text = "Error";
this.lblOutput.ForeColor = Color.Red;
}
}
This only allows me to enter one character and it has to be a number. Oh well, this will do..

Thanks for all the help guys
smile.gif
Now I get 10% of marks on my module
tongue.gif
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • K3Nv2 @ K3Nv2:
    I'll reformat and have a 3tb raid0 m. 2 at least
    +1
  • K3Nv2 @ K3Nv2:
    Lmao that sold out fast
    +1
  • Veho @ Veho:
    Yeet the cat.
    +1
  • K3Nv2 @ K3Nv2:
    Good idea
    +1
  • The Real Jdbye @ The Real Jdbye:
    i thought everybody knew cocktails are like 75% ice
  • Veho @ Veho:
    Yeah but not like this.
  • Veho @ Veho:
    It's not like they're complaining that their Slurpee is 99% ice or something, but if the cocktail calls for "shot of vodka, shot of vermouth, shot of gin, shot of Campari, three shots of juice, squirt of lemon" and ends up being a thimbleful of booze, that's a problem.
  • The Real Jdbye @ The Real Jdbye:
    the funny thing is cocktails in norway are only allowed to have 1 20ml shot of booze
  • The Real Jdbye @ The Real Jdbye:
    so..... yeah
  • The Real Jdbye @ The Real Jdbye:
    we're used to only having a thimbleful of booze
  • Veho @ Veho:
    Booo.
  • The Real Jdbye @ The Real Jdbye:
    same thing if you want whisky on the rocks or something, you can't get a double
  • The Real Jdbye @ The Real Jdbye:
    but you could buy as many shots of whisky (or anything else) as you want and ask for a glass of ice and pour them in
  • The Real Jdbye @ The Real Jdbye:
    it's dumb
  • Veho @ Veho:
    Maybe.
  • Veho @ Veho:
    There was a comparison of the number of Ibuprofen poisonings before and after they limited the maximum dosage per box or per pill (i'll look that up). No limit on the number of boxes you can still buy as many as you want, so people argued it was pointless.
  • Veho @ Veho:
    But the number of (accidental) poisonings dropped because drinking an entire package of ibuprofen pills went from "I need a new liver" to "I need a new box of Ibuprofen".
  • Veho @ Veho:
    Here we have ketoprofen that used to be prescription-only because of the risk of toxic dosages, but then they halved the dose per pill and sell them in bottles of six pills apiece instead of twenty and it doesn't need a prescription any more. Yes you can buy more than one bottle but people simply don't.
  • Psionic Roshambo @ Psionic Roshambo:
    Usually accidentally overdose of ibuprofen here is from people taking like cold medicine then ibuprofen for a headache and the combination is over what they need
    Veho @ Veho: https://imgur.com/gallery/QQkYnQu