Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. double transportationFootprint(double kmPerDay, double fuelEfficiency)
  8. {
  9.  
  10. double litresUsedPerYear = 365 * (kmPerDay / fuelEfficiency);
  11. double kgCO2 = (2.3 * litresUsedPerYear);
  12. return kgCO2;
  13. }
  14.  
  15. double electricityFootprint(double kWhPerMonth, int numPeopleInHome)
  16. {
  17. double kgCO2 = (kWhPerMonth * 12 * 0.257) / numPeopleInHome;
  18. return kgCO2;
  19. }
  20.  
  21. double foodFootprint(double meat, double dairy, double fruitVeggies, double carbs)
  22. {
  23. double kgCO2;
  24. double meat_kgCO2 = meat * 53.1;
  25. double dairy_kgCO2 = dairy * 13.8;
  26. double fruitVeggies_kgCO2 = fruitVeggies * 7.6;
  27. double carbs_kgCO2 = carbs * 3.1;
  28. kgCO2 = meat_kgCO2 + dairy_kgCO2 + fruitVeggies_kgCO2 + carbs_kgCO2;
  29. return kgCO2;
  30. }
  31.  
  32. double totalFootprint(double transportation, double electricity, double food)
  33. {
  34. double kgCO2;
  35. double tCO2 = (transportation + electricity + food) / 1000;
  36. kgCO2 = tCO2;
  37. return kgCO2;
  38. }
  39.  
  40.  
  41. int main ()
  42. {
  43. std::cout << std::fixed;
  44. std::cout << std::setprecision(2);
  45.  
  46. double kmPerDay1;
  47. double fuelEfficiency1;
  48. double transportationFootprint1;
  49.  
  50. double kWhPerMonth1;
  51. int numPeopleInHome1;
  52. double electricityFootprint1;
  53.  
  54. double meat_kgCO2;
  55. double dairy_kgCO2;
  56. double fruitVeggies_kgCO2;
  57. double carbs_kgCO2;
  58. double foodFootprint1;
  59.  
  60.  
  61. double totalFootprint1;
  62.  
  63.  
  64.  
  65. cout << "How many km do you drive in one day? ";
  66. cin >> kmPerDay1;
  67. cout << "What is the fuel efficiency rating of your car? ";
  68. cin >> fuelEfficiency1;
  69. transportationFootprint1 = transportationFootprint(kmPerDay1,fuelEfficiency1);
  70. cout << "Your Carbon footprint with respect to care use is " << transportationFootprint1 << "kg/year" << endl;
  71.  
  72. cout << "What is the average electricity consumption per month, in kilowatts? ";
  73. cin >> kWhPerMonth1;
  74. cout << "How many people live in the house? ";
  75. cin >> numPeopleInHome1;
  76.  
  77. electricityFootprint1 = electricityFootprint(kWhPerMonth1, numPeopleInHome1);
  78.  
  79. cout << "Your Carbon footprint with respect to electricity use is " << electricityFootprint1 << "kg/year" << endl;
  80.  
  81. cout << "Of all the food you eat, what percent consists of meat or fish? ";
  82. cin >> meat_kgCO2;
  83. cout << "Of all the food you eat, what percent consists of dairy products ";
  84. cin >> dairy1;
  85. cout << "Of all the food you eat, what percent consists of fruit and vegetables? ";
  86. cin >> fruitVeggies_kgCO2;
  87. cout << "Of all the food you eat, what percent consists of carbohydrates? ";
  88. cin >> carbs_kgCO2 >> endl;
  89.  
  90. foodFootprint1 = foodFootprint(meat_kgCO2, dairy_kgCO2, fruitVeggies_kgCO2, carbs_kgCO2);
  91.  
  92. cout << "Your Carbon footprint with respect to food consumption is " << foodFootprint1 << "kg/year" << endl;
  93.  
  94. totalFootprint1 = totalFootprint(transportationFootprint1, electricityFootprint1, foodFootprint1);
  95.  
  96. cout << "Your produce an annual total of " << totalFootprint1 << " metric tons of CO2 per year." << endl << "All done!";
  97.  
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement