Introduction
to Percentage Calculation
Calculating
percentages is a common task in various fields such as finance, mathematics,
and data analysis. In C++, we can develop a simple yet effective percentage
calculator program that takes two input values: the total value and the
percentage, and then computes the resulting percentage value.
Setting
Up the Program Structure
Before
diving into the code, let's outline the structure of our percentage calculator
program:
#include <iostream> using namespace std; int main(){ double ob, tm; cout<<"Enter obtained Marks: "; cin>>ob; cout<<"Enter total Marks: "; cin>>tm; double per=ob/tm*100; cout<<"Your Percentage is: "<<per <<" %"<<endl; if (per>100){ cout<<"Incorrect ob marks"<<endl; } else if (per>=80) { cout<<"Grade: A1"<<endl; } else if (per>=70) { cout<<"Grade: A "<<endl; } else if (per>=60) { cout<<"Grade: B"<<endl; } else if (per>=50) { cout<<"Grade: C"<<endl; } else if (per<=50) { cout<<"Grade: D"<<endl; } return 0; }
Input:
Prompt the
user to enter the total value and the percentage.
Calculation:
Calculate
the percentage value using the formula: percentage = (percentage / 100) *
total_value.
Output:
Display the
calculated percentage value to the user.
Implementing
the Percentage Calculator in C++
Now, let's
write the C++ code for our percentage calculator following the outlined
structure:
1 Comments
mashallah allah or tarakiaan de
ReplyDelete