Hi,
Sorry for the late reply, I was busy doing other things yesterday :+)
A simple 2d array of doubles with 3 rows and 3 columns looks like this:
1 2 3 4 5
|
double FishPrices[3][3] = {
{0.79,0.99,1.39},
{0.85,1.09,1.69},
{0.85,1.19,1.79}
};
|
To refer to the second row, second column:
std::cout << FishPrices[1][1]
remembering that array indices start at zero.
However a better approach may be to have a vector of structs.
1 2 3 4 5 6 7 8 9 10 11
|
struct FishPrice {
std::string Species;
double SizePrices[3];
};
std::vector<FishPrice> FishPriceTable = {
{"Bluegill", 0.79, 0.99, 1.39},
{"Redear Sunfish", 0.85,1.09,1.69},
{"Green Sunfish ", 0.85, 1.19, 1.79}
};
|
To refer to the largest sized "Redear Sunfish" :
std::cout << FishPriceTable[1].SizePrices[2];
In a similar fashion, refer to the species name with: FishPriceTable[1].Species;
So you could have a menu which returns a number which relates to the species - 1 in this case. There could also be a user input for the size - 2 in this case. Then you can look up the price and multiply by the quantity to arrive at a subtotal.
Remember that to make use of
std::string
and
std::vector
one has to include their header files:
1 2
|
#include <string>
#include <vector>
|
Also, make use of the reference material on this site - look at the links at the top left of this page.
Hopefully you can code the whole thing in 100 Lines Of Code (LOC) :+)