NEED HELP WITH C# PROBLEM: Redo problem 5 by adding a validation to check that t
ID: 3671084 • Letter: N
Question
NEED HELP WITH C# PROBLEM:
Redo problem 5 by adding a validation to check that the user's input is numeric. If not, prompt the user and ask them to re-enter the value(s).
I did the code for problem 5 already, but I need help adding the validation to check for user's input being numeric part.
I attached problem 5 below to refer to.
5. Write a console program that takes the x-y coordinates of a point in the Cartesian plane (typed in by the user from the keyboard) and displays a message telling either an axis on which the point lies (if x ory are 0, or the quadrant in which it is found. Sample output: (-1.0, -2.5) is in quadrant 2 (0.0, 4.8) is on the y axis Quadrant 4 Quadrant 1 Quadrant 3 Quadrant 2Explanation / Answer
Here is the code
using System;
public class Test
{
public static void Main()
{
String s;
double x,y;
bool f=true;
while(f)
{
Console.WriteLine("Enter x");
s=Console.ReadLine();
if(double.TryParse(s, out x))
{
Console.WriteLine("Enter y");
s=Console.ReadLine();
if(double.TryParse(s, out y))
{
if( x > 0 && y > 0)
Console.WriteLine("point lies in the First quandrant ");
else if( x < 0 && y > 0)
Console.WriteLine("point lies in the Second quandrant ");
else if( x < 0 && y < 0)
Console.WriteLine("point lies in the Third quandrant ");
else if( x > 0 && y < 0)
Console.WriteLine("point lies in the Fourth quandrant ");
else if( x == 0 && y == 0)
Console.WriteLine("point lies at the origin ");
else if( x == 0)
Console.WriteLine("point lies at y axis ");
else if( y == 0)
Console.WriteLine("point lies at x axis ");
f=false;
}
else Console.WriteLine ("Invalid Entry for y, please Try Again");
}
else Console.WriteLine ("Invalid Entry for x, please Try Again");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.