Here are the instructions:
.
- the outer loop processes vegetable categories
- the inner loop processes seasons within a vegetable category.
There are the same number of seasons for each vegetable category.
For a particular vegetable category in the outer loop, the inner loop will process all seasons, one by one.
- Input the number of seeds, the number of plants and the unit price of a plant.
- Keep a running total of:
- the growing ratio of plants to seeds
- the total selling price of all plants
At the end of the inner loop report the growing ratio and total selling price for that category
After all categories have been processed, report the following:
- The category of the best growing group (having the highest ratio)
- The category of the best selling price (having the largest sales)
SAMPLE DATA
Code:
Enter the number of the veg catagory :
2
Enter the number of the seasons :
2
----------------------------------------------------------
catagory 1 :
season 1 :
Enter Number of Seeds :
13
Enter Number of Plants :
11
Enter UnitPrice :
1.2
season 2 :
Enter Number of Seeds :
14
Enter Number of Plants :
10
Enter UnitPrice :
2.1
growing ratio for catagory 1 : 78.02%
total sold price for catagory 1 : 34.20
----------------------------------------------------------
catagory 2 :
season 1 :
Enter Number of Seeds :
12
Enter Number of Plants :
11
Enter UnitPrice :
1.1
season 2 :
Enter Number of Seeds :
14
Enter Number of Plants :
12
Enter UnitPrice :
1.4
growing ratio for catagory 2 : 88.69%
total sold price for catagory 2 : 28.90
----------------------------------------------------------
----------------------------------------------------------
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
Press any key to continue . . .
Here is my sample code:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num_of_veg_categories, num_of_seasons, seeds, plants, total_seeds, total_plants;
double unit_price, ratio_perc, total_price;
double bestRatio = 0; // ***set up for Ratio comparison
double bestAmount = 0; // ***set up for total sold price comparison
total_seeds=0;
total_plants=0;
total_price=0;
cout << setprecision(2) << fixed;
cout << "Enter the number of veg category: ";
cin >> num_of_veg_categories;
cout << "Enter the number of seasons: ";
cin >> num_of_seasons;
for (int i = 1; i <= num_of_veg_categories; i++) //*****Errors
{
cout << "Category" << i << ":" << endl;
for (int j = 1; j <= num_of_seasons; j++)
{
cout << "Season" << j << ":" << endl;
cout << "Enter the number of seeds: ";
cin >> seeds;
cout << "Enter the number of plants: ";
cin >> plants;
cout << "Enter the unit price: ";
cin >> unit_price;
total_seeds+=seeds;
total_plants+=plants;
total_price+= plants*unit_price;
}// ***seasons
ratio_perc= ( (double) total_plants / total_seeds) / num_of_seasons*100;
if (ratio_perc > bestRatio)
{
bestRatio = ratio_perc;
}
if (total_price > bestAmount)
{
bestAmount = total_price;
}
} //***outer loop
}
Why isn't my program actually working????