Write your question here.
Hi ! I am working on a code that will find the distance from a point on the Cartesian plane to the origin (0,0). As you can see this code does that. But I was wondering what I would have to do to alter the code so that the program only accepts positive numbers as x and y. I'm not great with user input validation and I was hoping someone might be able to help me out. Would it be best to use a while loop in the main portion of the code after the user inputs, x and y, or is it possible to input a while loop in the void setPoint portion of the code or in the double getPoint portions?
Thanks in advance for you help, I'm pretty new to this.
#include "stdafx.h"
#include <math.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Point coordinates;
double coordx, coordy;
double distance;
cout << "This Program will find the distance of a positive (first quadrant) point from the origin on the cartesian plane" << endl;
cout << "Please enter a positive value for 'x'" << endl;
cin >> coordx;
cout << "Please enter a positive value for 'y'" << endl;
cin >> coordy;
coordinates.setPoint1(coordx);
coordinates.setPoint2(coordy);