c++ Cartesian class not asking for user input -
my program supposed ask user input 2 sets of coordinates @ runtime. however, when compile , run it not ask input , instead gives me output
please enter first coordinates in form x y: please enter second coordinates in form x y: (0, 0) (0, 0)
how can fix this?
#include <iostream> #include <istream> #include <ostream> using namespace std; class cartesian { private: double x; double y; public: cartesian(double = 0, double = 0); friend istream& operator>>(istream&, cartesian&); friend ostream& operator<<(ostream&, const cartesian&); }; cartesian::cartesian(double a, double b) { x = a; y = b; } istream& operator>>(istream& in, cartesian& num) { in >> num.x; in >> num.y; return in; } ostream& operator<<(ostream & out, const cartesian& num) { cout << "(" << num.x << ", " << num.y << ")" << endl; return out; } int main() { cartesian coord1, coord2; cout << "please enter first coordinates in form x y: "; cin >> coord1; cout << "please enter second coordinates in form x y: "; cin >> coord2; cout << coord1; cout << coord2; return 0; }
on windows need specially configure project in order recieve input console
http://www.cplusplus.com/doc/tutorial/introduction/visualstudio/
Comments
Post a Comment