12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /*
- Copyright (c) 2015 Muhammad Moaz Imtiaz.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- using System;
- namespace EssenNote
- {
- class MainClass
- {
- public static int Main (string[] args)
- {
- try
- {
- Console.Write("Total Weight: ");
- double weight = double.Parse(Console.ReadLine());
- Console.Write("Total Carbohydrates: ");
- double carbs = double.Parse(Console.ReadLine());
- Console.Write("Sugars: ");
- double sugars = double.Parse(Console.ReadLine());
- Console.Write("Total Fat: ");
- double fats = double.Parse(Console.ReadLine());
- Console.Write("Total Protein: ");
- double protein = double.Parse(Console.ReadLine());
- double sugarPercent = (100*sugars) / weight;
- double fatPercent = (900*fats)/(9*fats+4*(protein+carbs));
- double overallGrade = PercentGrade(sugarPercent, fatPercent);
- Console.WriteLine(LetterGrade(overallGrade) + "\t" + Math.Round(overallGrade*100)/100 + "%");
- return 0;
- }
- catch(Exception e) {
- Console.Error.WriteLine ("Error: " + e.GetType ().ToString () + " occurred.");
- Console.Error.WriteLine ("Description: " + e.Message);
- return -1;
- }
- }
- protected static double PercentGrade (double sugarPercent, double fatPercent)
- {
- double _sugarPercent = 100 - sugarPercent;
- double _fatPercent = 100 - fatPercent;
- double resultantGrade = 2*((_sugarPercent * _fatPercent) / (_sugarPercent+_fatPercent));
- return resultantGrade;
- }
- protected static string LetterGrade (double overallGrade)
- {
- overallGrade += .5;
- if (overallGrade < 60)
- return "E";
- else {
- string mainGrade = new string[] { "D", "C", "B", "A" , "A" }[(int)Math.Floor(overallGrade/10)-6];
- mainGrade += (overallGrade % 10 < 3 && overallGrade != 100) ? "-" : (overallGrade % 10 >= 8 || overallGrade == 100) ? "+" : "";
- return mainGrade;
- }
- }
- }
- }
|