The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I can't seem to figure out why my project is not coming out with the output of the numbers I will provide below. Any help will or example can help in a big way. I would like to know how can I get my program to get these numbers. I cant seem to figure out why my loop always adds instead of erasing in each category I will provide my program can you tell me what I am doing wrong??
/*
Enter the number of the veg category :
2
Enter the number of the seasons :
2
----------------------------------------------------------
category 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 category 1 : 78.02%
total sold price for category 1 : 34.20
----------------------------------------------------------
category 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 category 2 : 88.69%
total sold price for category 2 : 28.90
----------------------------------------------------------
----------------------------------------------------------
The best growing group is Category 2, with the best growing ratio : 88.69%
The best total selling price is Category 1, with the price : 34.20
Press any key to continue . . .
*/
Â
Â
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int j;
double
double
double
double
double
double number_of_season;
number_of_veg_category;
currentTotalPrice = 0;
bestTotalPrice = 0;
currentRatio = 0;
bestRatio = 0; cout << "Enter the number of veg category: \n";
cin >> number_of_veg_category;
cout << "Enter the number of seasons: \n";
cin >> number_of_season;
cout << "------------------------------------------" << endl;
for (int i = 1; i <= number_of_veg_category; i++)
{
int seeds = 0;
int plants = 0;
int totalPlants = 0;
int totalSeeds = 0;
double unitprice = 0;
totalSeeds = seeds = 0;
totalPlants = plants = 0;
currentRatio += (plants*seeds);
currentTotalPrice += (plants * unitprice);
cout << "category " << i << ": " << endl;
for (j = 1; j <= number_of_season; j++)
{
int seeds = 0;
int plants = 0;
double unitprice = 0;
cout << "season " << j << ": " << endl;
cout << "Enter the number of Seeds : \n";
cin >> seeds;
cout << "Enter the number of plants: \n";
cin >> plants;
cout << "Enter the unit price: \n";
cin >> unitprice;
currentTotalPrice = currentTotalPrice;
}// ***seasons
cout << setprecision(2) << fixed;
cout << "growing ratio for category " << i << ": " <<
setprecision(2) << currentRatio << endl;
cout << "total sold price for category " << i << ": " <<
setprecision(2) << currentTotalPrice << endl;
cout << "--------------------------------------------" << endl;
if (currentRatio > bestRatio)
{
bestRatio = currentRatio;
}
if (currentTotalPrice > bestTotalPrice)
{
bestTotalPrice = currentTotalPrice;
} }
cout << "--------------------------------------------" << endl;
cout << "The best growing group is Category 2" << ", with the best growing
ratio : " << bestRatio << endl;
cout << "The best total selling price is Category 1" << ", with the
price : " << bestTotalPrice << endl;
return 0;
}
/*
Enter the number of veg category:
2
Enter the number of seasons:
2
-----------------------------------------category 1:
season 1:
Enter the number of seeds:
13
Enter the number of plants:
11
Enter the unit price:
1.2
season 2:
Enter the number of seeds:
14
Enter the number of plants:
10
Enter the unit price:
2.1
growing ratio for category 1: 71.43
total sold price for category 1: 34.20
-------------------------------------------category 2:
season 1:
Enter the number of seeds:
12
Enter the number of plants:
11
Enter the unit price:
1.1
season 2:
Enter the number of seeds:
14
Enter the number of plants:
12
Enter the unit price:
1.4
growing ratio for category 2: 85.71
total sold price for category 2: 63.10
--------------------------------------------------------------------------------------The best growing group is Category 2, with the best growing ratio : 85.71
The best total selling price is Category 1, with the price : 63.10
Press any key to continue . . .
*/