Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday 6 March 2017

Formula based program


Formula #9 (Calculate percentage and obtained value)

(a) Find percentage (b) Find obtained value
Enter your selection a/b: b
Enter total value: 500
Enter percentage: 86
Obtained Value: 430

The program for the formula is written in C# programming language and will accept a character as a case selection.
Case A) will help you to find the percentage for some obtained and total value data.
Case B) will help you to find the obtained value when you have/know the percentage value and total value data. Based on the formula it will find out the output.
 
Formula based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code these formula.

Practical Implementation:

using System;

namespace patternProblem.Formula
{
    class Formula9     //calculate percentage
    {
        static void Main(string[] args)
        {
            Console.Write("(a) Find percentage (b) Find obtained value \nEnter your selection a/b: ");
            string choice = Console.ReadLine().ToLower();
            double percentage = 0.0, obtainedValue = 0.0, totalValue = 0.0;

            switch (choice)
            {
                case "a":
                    Console.Write("Enter total value: ");
                    totalValue = Convert.ToDouble(Console.ReadLine());
                    Console.Write("Enter obtained value: ");
                    obtainedValue = Convert.ToDouble(Console.ReadLine());

                    percentage = ((obtainedValue * 100) / totalValue);

                    Console.WriteLine("Percentage: {0}%", percentage);
                    break;
                case "b":
                    Console.Write("Enter total value: ");
                    totalValue = Convert.ToDouble(Console.ReadLine());
                    Console.Write("Enter percentage: ");
                    percentage = Convert.ToDouble(Console.ReadLine());

                    obtainedValue = ((percentage * totalValue) / 100);

                    Console.WriteLine("Obtained Value: {0}", obtainedValue);
                    break;
                default:
                    Console.WriteLine("Invalid ! Selection");
                    break;
            }

            Console.ReadKey();
        }
    }
}

Output:
The input case will decide what you want to find either the percentage or the obtained value. So, based on the input case you’ll get the output. The output is shown below:

(a) Find percentage (b) Find obtained value
Enter your selection a/b: b
Enter total value: 500
Enter percentage: 86
Obtained Value: 430
Press any key to continue...


For any query, comment us below.

Skip to Main Table – Formula based program

Previous – Formulabased program #8

Next – Formula based program #10

Click imagination hunt to read latest blogs.


Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...