c# - Finding it difficult with the following code -
I have written to this place and I am stuck that I need help in ending or continuing a program .
What I mean is that when I ask questions, you want to withdraw today itself and if the answer is not there, the program should end, but if its, then it should be continued.
What am I missing? Please apply the aspect where the program should stop using N for a number in which I did not find the answer.
Namespace console application 1 {class program {static separable main (string [] args) {int zodiac = 20000; Int choice, pin = 0, x = 0; Console.light line ("enter your PIN"); Pin = int.Parse (Console.ReadLine ()); Console.light line ("Welcome to HSPUC Bank that you want to take back N or Y today"); Console.ReadLine (); }}}}
The user you are on the right track is the user you are denied The input is for taking and evaluating - this is the information received in this way:
line = Console.ReadLine ();
Your code might look like this:
int amount = 20000; Int choice, pin = 0, x = 0; Console.light line ("enter your PIN"); Pin = int.Parse (Console.ReadLine ()); Console.light line ("Welcome to HSPUC Bank that you want to take back N or Y today"); // Save User Input var userInput = Console.ReadLine (); // Evaluate if user wants to continue or not (userInput.ToLower () == "y") {// If yes, then go to console next. WrightLine ("Continue with other actions ..."); } // other goodbye consoles. Wrightite ("Bye");
The line for the PIN uses the user input! The same question can be made if you want to stay in the loop until the user wishes to take any more, instead you should see the if-else
More than is required. Take a look at do
and while
.
A solution might look like this:
// user input = y or n string choice; // user pin pin pin = 0; // state indicates that if the user wants to continue or not, then Bull continues Loop = false; Do {// Hello User Console. WrightLine ("Welcome to HSPUIC Bank that you want to withdraw N or Y today"); // Input options = console.readline (); // Check whether the user has entered the valid input if the option is to "do not continue the user" (like .olover () == "Y" option. ToLower () == "n") {// Default decision = Exit ContinuLoop = false; // If the user has been chosen to continue (liked. ToLower () == "y") {// User wants to do something, so continue to remain in the loop loop = true; // Ask for PIN Console. WrightLine ("Enter your PIN"); Var pinAsText = Console.ReadLine (); // Convert PIN to number: If (Intestate trippers (pinast text, out pin)) ... (Pinasset text == "1234") {Console.WriteLine ("pin right"); // continue with the logic here, for example, take the amount} and {console}. WrightLine ("wrong pin"); }}} Else {Console.WriteLine ("Please enter Y or N"); ContinuLoop = true; }} While (the current loop); Console.WriteLine ("Bye");
Now the flow looks like this:
Welcome to HSPQC Bank; Today you are N. & Y & G; & Gt; Enter YOUR PIN & gt; & Gt; 3 PIN incorrectly welcome you to HSPQIC Bank today; N or Y & G; & Gt; Enter YOUR PIN & gt; & Gt; 1234 Pin Welcome to HSPQC Bank Are you today N & Y & G; & Gt; N bye
Comments
Post a Comment