View Full Version : A basic percentage calculator
Hitterman
11-07-08, 04:41 PM
You may have to calculate percentage of your subjects in schools. However you can do that in copy but here is a simple tutorial on Making Percentage calculator in c++. This calculator is for 5 Subjects.
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
float a,b,c,d,e,f;
cout<<"Marks in English"<<endl;
cin>>a;
cout<<"Marks in Maths"<<endl;
cin>>b;
cout<<"Marks in Physics"<<endl;
cin>>c;
cout<<"Marks in Chemistry"<<endl;
cin>>d;
cout<<"Marks in Computers"<<endl;
cin>>e;
clrscr();
cout<<"Total of Marks "<<a+b+c+d+e<<endl;
cout<<"Total Percentage "<<(a+b+c+d+e)/5<<" % "<<endl;
getch();
}
cout: This command lets you to print text on the screen when you run the Application.
cin:Allows you to add dynamic values in your program.
float: A vaiable only used if your program has decimal values.
More coming soon
Using the techniques from this you can try more things like Biodata form.
Good tutorial there Hitty!
Can we add more subjects hitty?
halogen19
13-07-08, 12:12 AM
I didn't know a programmer could be this stupid. To calculate percentage you'll have to do (a+b+c+d+e) * 100 / 5! a+b+c+d+e / 5 is just the average, not the percentage! You don't even know the basic formulas?
Why do you have to load stdio and iostream both? stdio is only for C and not C++!
Hitterman
13-07-08, 07:51 PM
Even the most stupid programmer can easily get that when you take out percentage o ffive subjects 100 each then dividing by 5 or /500 * 100 is Same. I have just simplified it rather than writing the full formula and about stdio its not required here but if you wanted to add advanced commands for alligning etc it is useful.
Abhinav
13-07-08, 09:02 PM
Even the most stupid programmer can easily get that when you take out percentage o ffive subjects 100 each then dividing by 5 or /500 * 100 is Same. I have just simplified it rather than writing the full formula and about stdio its not required here but if you wanted to add advanced commands for alligning etc it is useful.
No, its not. stdio.h is the header file used for C programs. You have written this program in C++ so there is no need for stdio.h
Other than that the program is nice for beginners. But its not a tutorial since it doesn't explain how it works. The purpose of a tutorial should be to enable others to learn rather than encourage them to copy-paste.
Hitterman
13-07-08, 09:15 PM
Okay i'll remove stdio.h
Other than that the program is nice for beginners. But its not a tutorial since it doesn't explain how it works. The purpose of a tutorial should be to enable others to learn rather than encourage them to copy-paste.
I agree with you, I just have written what i knew about C++ as i am also not very advanced in c++.
Thanks:)
-
Shreyas
06-01-09, 08:45 PM
Here is an improvement over it:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int buffer;
float percent;
int totMarks;
int totMaxMarks;
int subjects;
totMarks = 0;
totMaxMarks = 0;
cout << "Enter number of subjects: ";
cin >> subjects;
subjects = subjects;
cout << "\n\n";
int i;
for(i = 1;i <= subjects; i++)
{
cout << "Enter marks for Subject " << i << ": ";
cin >> buffer;
totMarks = totMarks + buffer;
cout << "Enter maximum marks for Subject " << i <<": ";
cin >> buffer;
totMaxMarks = totMaxMarks + buffer;
cout << "\n\n";
}
percent = totMarks * 100 / totMaxMarks;
cout << "Your Percentage: " << percent << "\n\n\n";
main();
return 0;
}
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.