TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shane Stapleton
NA
6
2.6k
Cornhole Calculator
Aug 29 2016 6:58 PM
Hey guys so I'm pretty new at C#. Right now I am trying to create a cornhole calculator (you know, the game where you throw bean bags into a hole). I have the GUI created and some of the coding done, but I can't figure out my current problem which is that my variable that adds up the Total Points for each team resets back to 0 every time. I'm not sure how to update it to where it keeps adding to the total score every time I add a new number in and click my "Add" button.
Anyways, here's my code that I have so far.
public MainPage()
{
this.InitializeComponent();
}
private void addTeamPoints(object sender, RoutedEventArgs e)
{
int oneAdd = int.Parse(teamOneAdd.Text);
int twoAdd = int.Parse(teamTwoAdd.Text);
int oneTotal = 0;
int twoTotal = 0;
if (oneAdd > 0)
{
oneTotal += oneAdd;
teamOnePoints.Text = oneTotal.ToString();
}
else if (twoAdd > 0)
{
twoTotal += twoAdd;
teamTwoPoints.Text = twoTotal.ToString();
}
else
{
string ex = "Enter a number higher than 0";
exception.Text = ex;
}
teamOneAdd.Text = "0";
teamTwoAdd.Text = "0";
}
So there's a Textbox that is automatically set to 0 and then you input a number in to change whichever team's total. There can't be a number higher than 0 in both boxes and both boxes can't be equal to zero. Then, after it updates the total score the box should change back to 0 so you can enter in a new number.
I am also trying to figure out how to not let the total equal over 21 and if it does then it resets the total back to 15 (because the team busted).
Reply
Answers (
3
)
Productionalize approach for MongoDB
how to sort student by Total degrees as 1st - 2nd - 3rd