I keep on getting an error in the last part of my int main portion of my program and i cannot figur out what is wrong i will post my code here but what i am trying to do is get the program to display the volume of each box and the combined volume for the boxes but when i use the cout << endl it says that there is no storage class or type specifier for this declaration i get the same on line please help
#include <iostream>
using std::cout;
using std::endl;
class CBox
{
public:
double m_Length;
double m_Width;
double m_Height;
double Volume()
{
return m_Length*m_Width*m_Height;
}
};
int main
{
CBox box1; //declare box1 of type CBox
CBox box2; //declare box2 of type CBox
CBox box3; //declare box3 of type CBox
double boxVolume = 0.0; // Stores the volume of a box
box1.m_Height = 18.0; // Define the values
box1.m_Length = 78.0; // of the members of
box1.m_Width = 24.0; // the object box1
box2.m_Height = box1.m_Height - 10; // Define box2
box2.m_Lenght = box1.m_Length/2.0; // members in
box2.m_Width = 0.25*box1.m_Length; // terms of box1
box3.m_Height = box1.m_Width*1.5; // Define box3
box3.m_Length = box1.m_Length/3; // members in
box3.m_Width = box1.m_Height*1.5; // terms of box1
boxVolume = box1.Volume(); //calulates the volume of box1
// calculate total volume of box 1-3
cout << endl
<<"The volume of box1 = " << boxVolume;
cout << endl
<<"Volume of box2 = " << box2.Volume();
cout << endl
<< "Volume of box3 = " << box3.Volume();
cout << endl
<< "The total volume = " <<box3.Volume()*box2.Volume*boxVolume;
cout << endl
<< “A CBox object occupies “
<< sizeof box1 << “ bytes.”;
cout << endl;
#include <iostream>
using std::cout;
using std::endl;
class CBox
{
public:
double m_Length;
double m_Width;
double m_Height;
double Volume()
{
return m_Length*m_Width*m_Height;
}
};
int main ()
{
CBox box1; //declare box1 of type CBox
CBox box2; //declare box2 of type CBox
CBox box3; //declare box3 of type CBox
double boxVolume = 0.0; // Stores the volume of a box
box1.m_Height = 18.0; // Define the values
box1.m_Length = 78.0; // of the members of
box1.m_Width = 24.0; // the object box1
box2.m_Height = box1.m_Height - 10; // Define box2
box2.m_Length = box1.m_Length/2.0; // members in
box2.m_Width = 0.25*box1.m_Length; // terms of box1
box3.m_Height = box1.m_Width*1.5; // Define box3
box3.m_Length = box1.m_Length/3; // members in
box3.m_Width = box1.m_Height*1.5; // terms of box1
// calculate total volume of box 1-3
cout << endl
<<"The volume of box1 = " << box1.Volume ();
cout << endl
<<"Volume of box2 = " << box2.Volume();
cout << endl
<< "Volume of box3 = " << box3.Volume();
cout << endl
<< "The total volume = " << box3.Volume() * box2.Volume () * box1.Volume ();
cout << endl
<< "A CBox object occupies " << sizeof (box1) << " bytes." << endl;
cout << "Press ENTER to end the program." << endl;
std::cin.get ();
return 0;
}
It gave me this output
The volume of box1 = 33696
Volume of box2 = 6084
Volume of box3 = 25272
The total volume = 5.18092e+012
A CBox object occupies 24 bytes.
Press ENTER to end the program.
I deleted boxVolume because there was no point of having it. You should have just used box1.volume
All your errors were syntax so they were easy to find.
I like your project idea though.
Hope this helps :)
Dude u are a life saver
so what exactly was wrong with it like what all did i leave out cus i see that u added the std::cin.get (); at the end and removed but what all did i do wrong so i can learn from it if u have the time please
Well you misspelled box2.m_Length
and when you were printing cout << "The total volume = " << box3.Volume() * box2.Volume () * box1.Volume ();
You printed out cout << "The total volume = " << box3.Volume() * box2Volume * box1Volume;
And your class hand an extra bracket
That is all of your errors I found.
Happy to help.
:)