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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// <--- Most comon includes.
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
void plantInput(int& size);
int main()
{
int size{};
plantInput(size);
// <--- Keeps console window open when running in debug mode on Visual Studio. Or a good way to pause the program.
// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point.
}
void plantInput(int& size)
{
constexpr int PEACH{ 1 }, TOMATO{ 2 }, APPLE{ 1 }, MANGO{ 4 };
//int n{ 3 }, i, s{}, iP{}, iT{}, iA{}, iM{}, input_size{}, input_size2{}, input_size3{}, input_size4{}, psize, tsize, asize, msize;
int n{ 3 }, input_size{};
std::string input{ "peach" }; // , Peach, Tomato, Apple, Mango;
size = 0; // <--- Changed.
std::cout << "\n The available plants are: (Peach, Tomato, Apple and Mango)\n"; // <--- Changed.
//std::cout << "\n How many plants would you like to use?: ";
//std::cin >> n;
for (int lc = n; lc > 0; lc--)
{
std::cout << "\n Now input what plant you would like to harvest: "; // <--- Changed.
std::cin >> input;
if (input == "Peach" || input == "peach") // <--- Changed.
{
std::cout << "\n Size: 1 x 1 ";
std::cout << "How many peaches would you like to plant? ";
std::cin >> input_size;
//input_size = iP; // <--- input_size is never used after this point right now.
//psize = 1 * iP;
//size += psize;
size += PEACH * input_size;
//n = n - input_size; // <--- Not sure what to do with this?
}
if (input == "Tomato" || input == "tomato") // <--- Changed.
{
std::cout << "\n Size: 2 x 2 ";
std::cout << "How many peaches would you like to plant? ";
std::cin >> input_size;
//input_size = iT; // <--- input_size is never used after this point right now.
//psize = 1 * iT;
//size += psize;
size += TOMATO * input_size;
//n = n - input_size; // <--- Not sure what to do with this?
}
}
std::cout << "\n You have chosen " << size << " square feet of plants to harvest " << "\n" << std::endl;
}
|