0

#include <iostream>
#include <cmath>
using namespace std;

class Rectangle {
public:
int width, height;
Rectangle();
~Rectangle();
double r_area();
double r_perimeter();
};


Rectangle::Rectangle()
{
width = 1;
height = 1;
}
Rectangle::~Rectangle()
{
}

double Rectangle::r_area()
{
return (width * height);
}

double Rectangle::r_perimeter()
{
return (2*width + 2* height);
}

int main ()
{
cout<< "Defaults:" << endl;
Rectangle r;
cout << "Rectangle area = " << r.r_area() << " Perimeter = " << r.r_perimeter() << endl;
cout << "Rectangle: Please enter length and width: ";
cin >> r.height, r.width ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ERROR
cout << "Rectangle area = " << r.r_area() << " Perimeter = " << r.r_perimeter() << endl;

system("pause");
return 0;
}

I am trying to take a user input for width and height but I have a problem in the Cin;
Any ideas?
thanks :)

Edited by d0c: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Chilton
0

As caut mentioned, you can't read in with a comma. In addition, you could always make the class variables private and use a member function to set them rather than allowing main() direct access to them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.