C# Calculator Text Input Validation [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am currently writing a calculator application. One part of this application is a Simple Calculator that works like the calculator in windows (using windows 8). It can parse the numbers entered in the textbox. However, if the user does not enter in the correct form such as 5 * * 5 it will give an error. I want it to check the character entered before to see if its an operator and if it is, replace it such as 5 * / 5 to become 5 / 5 as the user is typing. Also it will need to check the parenthesis are in the correct order such as () or () not )(. The other thing it will need to check is that the number being entered only has one decimal point. For example, 4.38585 + 5.32948. I have already limited key entries to only numbers and operators. I have checked this for some time now, but have not seen any solutions.

If you're going to allow the user to enter an expression and then make him press a "calculate" button, then you should not validate things on the fly. Let the user make mistakes, since he will anyway. The user will want to go back and edit the text that he's entered. Your editing rules will make that difficult or impossible. Or worse, inconsistent.
For example, say that the user enters 4.35*7.29.
Then he realizes that he wanted to divide. But your editing rules won't let him delete the * because that would make for an invalid number. And he can't enter the / first and then delete, because doing so would give /* or */, both of which are invalid. Are you going to allow the temporary invalid expression when editing, but not allow it when the user is typing? That would be inconsistent, and wouldn't prevent your evaluator from having to do the error checking again and notify the user.
Limit keystrokes to numbers and operators if you like, but don't try to validate the form of what the user inputs. Let him type **)9(// if he wants. Handle the error when you're parsing--AFTER the user has pressed the calculate button.
Now, if your application works like Windows Calculator in that it keeps a running total as the user enters values and operators, that's a different matter. But what you're talking about would just be frustrating. I certainly wouldn't want to use it.

Related

Game to determine odd, even and prime numbers within text strings c#

Here are the steps of the problem with examples in relation to the first part of the problem:
1 - The program asks the user to enter the number of questions to be asked.
2 - For each question, the program asks the user to enter a valid value between 3 and 100 that helps determine the number of symbols
generative
Randomly and the duty is to enumerate a number of numbers (odd, even or prime) according to the text of the question within this series
of icons. This value is an indicator of how difficult the question is.3- Each question is synthesized by merging several randomly generated codes. Symbols include uppercase letters
and small and numbers from 0 to 9. And then ask the user to specify a number for numbers (odd, even or prime) within
randomly.
this series. Determining the type of numbers to be counted (odd, even or prime) is also done
4 - For each question asked, the string generated is stored in an array and the question pattern is in a second array (pattern is
A question about odd numbers, a question about even numbers, or a question about prime numbers), the result is calculated and stored
correct results in a custom array in order to store the correct results, then the question is asked to the user and stored
The answer is in a custom matrix of user answers.For each question asked, the generated string is stored in an array and question pattern
For each question that is asked to the user, the answer is evaluated, and the evaluation result corresponding to each question is stored in
Matrix for evaluation of results. If the evaluation result is correct, the value 1 is stored, otherwise the value 0.
For any question the user can ignore the question but it is recorded as wrong answer.
The word to ignore the question is Ignore, and here the treatment should be (insensitive case.)
Prime numbers are integers greater than one and are only divisible by themselves.Regarding the second part of the question:
After the user is asked questions and answers are stored, the user can choose as many functions as possible
It performs statistical operations on the results stored within the arrays. Like the number of correct answers, the number of wrong answers.
These options are displayed repeatedly until the user types exit and the program ends.
The word to terminate the program is exit and here the treatment should be (insensitive case.)
The options are:
Display the number of wrong answers.
Display the number of correct answers.
Display the questions, the user's answers to them, and the correct answers corresponding to each question.
Option exit to end displaying options and exit the program

How can I clear my textboxes in my Windows Presentation Foundation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an Application build in WPF. It have a Textbox that will always accept only 10 digits and is always ready for Scanning ID Barcode Contains 10 Digits or Entering Number with Keyboard.
Now some Customers are entering just 2 digits and leaving system as it is. Let us say he write 12 in TextBox and left it. When new Customer is coming he is Scanning his Id without noticing that there is something already written in the TextBox. So New Number is coming like this 1224444444 and two numbers are missing that is 34.
How can I clear Textbox before Scanning or Before Writing?
some example code of exactly how you are attempting this would be useful.
A WPF textbox can be cleared by either calling the .Clear method, or simply by setting the "Text" property of the Textbox to string.empty.
With regards to most barcode scanners i've seen and used (usually KB emulation), you can usually set them up to get a prefix and suffix on the data so that you can detect scan input over keyboard input. You can then detect a scan and clear the textbox prior to entering the new information
react at the new scanevent from the barcodescanner and clear the textbox.text with string.empty

how can i change the password character of the textbox during runtime [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my log-in form and under that there's also the "Change Password" my teacher recommended me that if I write my old password in the old password textbox i'll see the characters, but if I leave that textbox and go to the new password textbox the characters should turn into "*".
How can I make that possible ?
Firstly, by convention there's no need to do this. The only reason that happens on mobile devices is that it's very easy to type wrong characters on tiny keyboards with large fingers. Getting a chance to quickly preview the last typed character is highly desirable. On a WinForms app I've never come across that usability. But, if you really want to do it, you'll need to create a custom control. The problem is that the PasswordChar property will mask all characters, not just all but the last one.
You could perhaps inherit from TextBox and add a property called TimedPasswordChar. Then subscribe to the ValueChanged event. In this handler, if TimedPasswordChar is not null or empty then start a Timer object with a 1000ms interval. In the Tick event handler, stop the timer on the first line the convert the last character to the TimedPasswordChar. Bear in mind though that you will need to add each character you switch to the TimedPasswordChar to a private member variable holding the actual password. I'd suggest using System.Security.SecureString given it's a password.
Just before you convert the last char to the TimedPasswordChar then add the entered value with .AppendChar(...).
One point that complicates it though is if the user edits the string. You need to monitor which string has been edited and then use .RemoveAt(...) on the secure string to keep it in sync.

How to validate a Text in Asp.net [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to put check to validate textbox that input value must not be similar to the values already present in database. Like:
if there is value with text "Hello" in database then user must not be allowed to save value either he writes:
Hello
HELLO
hElLo
HeLLO
Hello etc
I followed this http://www.dotnetperls.com/string-isupper-islower but as i am new to c# so have little confuse that how to match above defined words as all are same words Hello
I typically just convert both values (user input and stored value) to lower case when making the comparison.
Edit: if both values are in .NET, you could use String.Compare(s1, s2, StringComparison.OrdinalIgnoreCase)
Do you need to do this in code? I would suggest that you just make a unique constraint on the column and let the database handle that for you. Depending on the database you are using you may need to do a little additional work to handle the case sensitivity.

Creating an application for Math Practice with ASP.NET [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am trying a develop a Math Practice web application using ASP.NET (not MVC), which allows Users to perform Multiple choice or simply type an answer, click a button and see answer.
The first idea that comes to mind is simply get permission to use a book, grab all the questions and answers using a DB and display the right answer. But how would I display the answer or the show me how the answer was derived.
My confusion is; how does this work?:
Do I have to write all the formulas and answer myself?
Are there programs for this?
I do not even know where to start.
What I would like to do is have the user select an answer, if the answer is wrong, they can click the show me button.
I am looking to either write this in C#, Visual Basic using JQuery on the front end.
Just need some direction.
Thanks my friends.
When I was in college I had to do something very similar.
What I did is stored expressions 4 + 5; 1 * 6 in database and then pushed those expressions to evaluate on run-time because it is pretty easy in C#.
It takes expression from database 2 + 2
It evaluates the expression on run-time producing result 4
You get your result and show it to user or do whatever with it
More info on how exactly to do that: http://www.c-sharpcorner.com/UploadFile/mgold/CodeDomCalculator08082005003253AM/CodeDomCalculator.aspx
I don't think you need to evaluate a stored expression. Since you just want the user to enter multiple choice or the answer itself, just set up your database as follows:
QuestionAnswers:
ID (uniqueidentifier) (primary)
QuestionText (varchar)
QuestionAnswer (varchar)
ShowMeHowEquation (varchar)
Then, display the ShowMeHowEquation via jQuery like so:
Show Me How
<div class="showMeHowEquation">Database driven contents here...</div>
<script>
$(document).ready(function() {
$('.showMeHow')click(function() {
$(this).next('.showMeHowEquation').slideDown();
});
});
</script>

Categories