0

I am receiving three c2228 errors when I try to compile my program.
*edit* I am dealing with rectangular prisms in this program.*edit*
Here is my code:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

class Rect
{
   private:
	double length;
	double width;
	double hight;
   public:
	Rect(double l = 1.0, double w = 1.0, double h = 1.0)
	{
		length = l;
		width = w;
		hight = h;
	}
	void setnewvalues(double, double, double);
	void volume(double, double, double);
	void area(double, double, double);
	void showvalues(double, double, double);
};

void Rect::setnewvalues(double l, double w, double h)
{
	length = l;
	width = w;
	hight = h;

	return;
}

void Rect::volume(double l, double w, double h)
{
	double volume;

	length = l;
	width = w;
	hight = h;

	volume = length * width * hight;

	cout << " " << volume << " ";

	return;
}

void Rect::area(double l, double w, double h)
{
	double area;

	length = l;
	width = w;
	hight = h;

	area = (4 * (length *  width)) + (2 * (width * hight));
	
	cout << area << endl;

	return;
}

void  Rect::showvalues(double l, double w, double h)
{ 
	length = l;
	width = w;
	hight = h;
		
	cout << setw(6) << length << " " << setw(5) << width <<  " " 
		 << setw(5) << hight;

	return;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Rect recta(double l, double w, double h);

	cout << "length width hight volume area\n" 
		 << "------ ----- ----- ------ ----" << endl;
	
	recta.showvalues();
	recta.volume();
	recta.area();
	
        return 0;
}

lab11makir.cpp(86) : error C2228: left of '.showvalues' must have class/struct/union
lab11makir.cpp(87) : error C2228: left of '.volume' must have class/struct/union
lab11makir.cpp(88) : error C2228: left of '.area' must have class/struct/union

Any suggestions or help would be appreciated. Thank you.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Duoas
1

Always fix errors in the order they come. Line 81 is incorrect, so no variable named recta is ever created, so when the compiler hits line 86 it complains about some structure variable you are using that doesn't exist.

Try this instead: Rect recta( 12.9, 13.4, 7.6 ); Also, please avoid MS stuff whenever possible. Your main function should be typed: int main( int argc, char *argv[] ) At the time MS wrote all those macros and junk, they had a pretty good reason. But there is no reason to contaminate new, unrelated code with it.

Hope this helps.

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.