Question: I need help with making the very bottom comment come to life: //The best growing group is Catagory 2, with the best growing ratio

I need help with making the very bottom comment come to life: "

//The best growing group is Catagory 2, with the best growing ratio : 88.69%

//The best total selling price is Catagory 1, with the price : 34.20".

Not so much this information exactly. I just need my program to work in the same way with appropriate and legal numbers inputted.

1) How would I get the program to figure out which category is the largest? We must assume there can be more than two categories. No limit was given.

2) Also need it to be displayed just like the comment states.

Any help would be appreicated. Thank you.

#include // allows program to perform input and output

#include

using std::cout; // program uses cout

using std::endl; // program uses endl

using std::cin; // program uses cin

int main()

{

int numberSeeds, numberPlants, numberOfCategories, numberOfSeasons, i, j, k = 0, l = 0, m = 0, n =0;

double unitPrice, totalSoldPrice, ratio, totalPlants, totalSeeds;;

totalPlants = totalSeeds = 0;

totalSoldPrice = 0;

cout << "Enter the number of the veg category : ";

cin >> numberOfCategories;

cout << "Enter the number of the seasons : ";

cin >> numberOfSeasons;

cout << "------------------------------------------------- ";

while (n == 0)

{

if ((numberOfCategories < 0) || (numberOfSeasons < 0))

{

cout << "Error. Cannot have a negative number of categories or seasons. Try again. ";

}

else

n = 1;

}

for (i = 1; (numberOfCategories != 0) && (i <= numberOfCategories); i++)

for (j = 1; (numberOfSeasons != 0) && (j <= numberOfSeasons); j++)

{

cout << "Category " << i << " : ";

cout << "Season " << j << " : ";

while (l == 0)

{

cout << "Enter Number of Seeds : ";

cin >> numberSeeds;

if (numberSeeds < 0)

{

cout << "Error. Cannot have a negative amount of seeds. Try again. ";

}

else

l = 1;

}

while (k == 0)

{

cout << "Enter Number of Plants : ";

cin >> numberPlants;

if ((numberPlants > numberSeeds) || (numberPlants < 0))//if thiscondition is true error message will be displayed and k will not be //changed, therefore the loop will run again to take input numberPlants.

{

cout << "Error. Amount of plants cannot exceed number of seeds and/or be negative. Try again. ";

}

else//if condition is false k becomes 1 and execution gets out of while loop

k = 1;

}

while (m == 0)

{

cout << "Enter UnitPrice : ";

cin >> unitPrice;

if (unitPrice < 0)

{

cout << "Error. Price per item cannot be negative. Try again. ";

}

else

m = 1;

}

k--;

l--;

m--;

totalSeeds += numberSeeds;

totalPlants += numberPlants;

totalSoldPrice += (numberPlants * unitPrice);

ratio = (totalPlants / totalSeeds) * 100;

//cout << "Error. Amount of plants cannot exceed number of seeds. Try again. ";

if (numberOfSeasons == j)

{

cout << "Growing ratio for category " << i << " : " << std::setprecision(4) << ratio << "% "

<< "Total sold price for category " << i << " : " << std::setprecision(5) << totalSoldPrice << endl

<< "------------------------------------------------- ";

}

}

if (numberOfCategories == 0 && numberOfSeasons == 0)

cout << "Zero categories and seasons entered. ";

else if (numberOfCategories == 0 || numberOfSeasons == 0)

cout << "Either zero categories or seasons entered. ";

//----------------------------------------------------------

//The best growing group is Catagory 2, with the best growing ratio : 88.69%

//The best total selling price is Catagory 1, with the price : 34.20

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!