You beat me to my reply. ;-)
Originally Posted by
noobkiddo
my program is already running but how can I do:
4) that instantiates a Carpet object
5) and assigns values to its fileds.
6) Pass the object to a function named Area()
To instantiate and object means to create an instance of that object. That is, you can't use Carpet directly. Think of Carpet as any other data type, like an int or float. You can't do:
Code:
int = 5
float = 3.14
It's the same for structs. You need to create an object of type Carpet:
Code:
Carpet myCarpet;
Carpet persianRug;
Once you have a Carpet object, you can do things to it. In your Carpet struct, you have two data fields, lengthInFeet and widthInFeet. To use them, you use the dot operator:
Code:
Carpet myCarpet;
myCarpet.lengthInFeet = 11.0;
myCarpet.widthInFeet = 7.5;
cout << "Length in feet: " << myCarpet.lengthInFeet << endl;
cout << "Width in feet: " << myCarpet.widthInFeet << endl;
Lastly, you pass a struct like any other variable:
Code:
float Area(Carpet myCarpet)
{
//stuff
}
int main()
{
Carpet persianRug;
//stuff
cout << "Area of carpet: " << Area(persianRug);
return 0;
}