Mar 20, 2012 at 12:07pm UTC
this is what i wrote so far:
#include <iostream>
using namespace std;
void getData(int & theHeight, int & theLength, int & theWidth)
{
cout << "Enter the height: ";
cin >> theHeight;
cout << "Enter the width: ";
cin >> theWidth;
cout << "Enter the length: ";
cin >> theLength;
}
void calculateVolume(int theHieght, int theLength, int theWidth)
{
theVolume = << theHeight >> * << theLength >> * << theWidth >>;
}
void displayOutput(int theHeight, int theLength, int theWidth, int theVolume)
{
if (theVolume < 100)
cout << "Small";
if ((theVolume >= 100) && (theVolume <= 500))
cout << "Medium";
if (theVolume > 500)
cout << "Large";
}
int main ()
{
int theHeight;
int theWidth;
int theLenght;
int theVolume;
for (int i = 0; i < 5; i++)
{
getData(theHeight, theWidth, theLength);
theVolume = calculateVolume(theHeight, theWidth, theLength);
displayOutput(theHeight, theWidth, theLength);
}
return 0;
}
what is wrong with it? i cant compile, dont know where i made my mistake.
Mar 20, 2012 at 12:13pm UTC
put your code in [ code] [ / code] tags
and
post your error, your compiler is shooting you a message.
Mar 20, 2012 at 12:46pm UTC
Something like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#include <iostream>
#include <limits>
using namespace std;
#define CLRJUNK cin.ignore();
#define PROMPT cout << "<Press ENTER KEY to continue>";
#define PAUSE cin.ignore(numeric_limits<streamsize>::max(), '\n' );
void getData(int & theHeight, int & theLength, int & theWidth)
{
cout << "Enter the height: " ;
cin >> theHeight;
cout << "Enter the width: " ;
cin >> theWidth;
cout << "Enter the length: " ;
cin >> theLength;
}
void calculateVolume(int &theHeight, int &theLength, int &theWidth,int &theVolume)
{
theVolume = theHeight * theLength * theWidth ;
}
void displayOutput( int &theVolume)
{
if (theVolume < 100)
cout << "Small" <<endl;
else if ((theVolume >= 100) && (theVolume <= 500))
cout << "Medium" <<endl;
else if (theVolume > 500)
cout << "Large" <<endl;
}
int main ()
{
int theHeight=0;
int theWidth=0;
int theLength=0;
int theVolume=0;
int amount=0;
cout << "How many time you want to run this: " ;
cin >> amount;
for (int i = 0 ; i < amount;i++)
{
getData(theHeight, theWidth, theLength);
calculateVolume(theHeight, theWidth, theLength,theVolume);
displayOutput(theVolume);
}
CLRJUNK;
PROMPT;
PAUSE;
return 0;
}
Last edited on Mar 20, 2012 at 1:27pm UTC
Mar 20, 2012 at 1:50pm UTC
@en liten kille - Should , yes, as good programming practice. However, it won't cause that much of a problem. They're being passed into a function by reference almost immediately after and then (providing the user input is correct) are getting assigned values in that function.
To the OP, yeah, if you're more specific with your errors it would make helping you out a lot easier.
I can tell you that your calculateVolume function is doing jack, though. You're assigning it to a value (theVolume) but the function doesn't actually return anything. So, if it did compile, you wouldn't get the results you're after.
The compilation error is probably going from that crazy syntax inside of the calculateVolume function. Why are you using the '<<' and '>>' operators?
Last edited on Mar 20, 2012 at 4:32pm UTC