void displayLargestAvgArea( double circle, double square, double rect, double triangle )
{
// An array of four 'double', initialized with the variables whose were passed into the function
double vArea[4] = { circle, square, rect, triangle };
// An array of four std::string objects
std::string vName[4] = { "circle", "square", "rectangle", "triangle" };
double max = 0;
int pos = 0;
// idx is just a (arbitrary choiced) name of an int variable.
// It's meant to be an abbreviation of 'index'.
for (int idx = 0 ; idx < 4; ++idx)
{
if (vArea[idx] > max)
{
max = vArea[idx];
pos = idx;
}
}
std::cout << "The largest area has the " << vName[pos]
<< ". It has an area of " << max << " units.\n";
}
}
void LargestAvgArea(double avgCircle, double avgSquare, double avgRectangle)
{
//i need to compare each of the randomized average areas above and then display
}
void SmallestAvgArea(double avgCircle, double avgSquare, double avgRectangle)
{
//i need to compare each of the randomized average areas above and then display
}
I am still quite new with c++, so I don't get what idx is.
If you would please write comments on what things are in the codes you provided, that would help me understand the language more!
Hello gongong, sorry to hear that it is not allowed to you, using arrays. Because without them you are forced to use a bunch of if-else brunches.
Btw: The function I wrote, consists of very basic c(++) stuff. I added some comments in the hope that it would be clearer to you. I guess you stumbled over the definitions and usings of the two arrays. For understanding what's going on there, I recommend you for seaching a good tutorial which handles pointers and arrays. Sorry for my insufficient knowledge of the englisch language. That's the reason why I rather provide with code than with good explanations.