   ## Monday, 6 March 2017

### Formula based program

Formula #9 (Calculate percentage and obtained value)

(a) Find percentage (b) Find obtained value
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.

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: ");
double percentage = 0.0, obtainedValue = 0.0, totalValue = 0.0;

switch (choice)
{
case "a":
Console.Write("Enter total value: ");
Console.Write("Enter obtained value: ");

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

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

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

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

}
}
}

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 total value: 500
Enter percentage: 86
Obtained Value: 430
Press any key to continue...

For any query, comment us below.

Previous – Formulabased program #8

Next – Formula based program #10

Click imagination hunt to read latest blogs.

Keep learning and sharing... 