here is the code for this
#include <iostream>
#include <stdlib.h>
using namespace std;
int obtain_marks;
int total_marks;
int percentageoutput;
void percentage(){
cout << "Enter obtain marks"<<endl;
cin >> obtain_marks;
cout << "Enter total marks"<<endl;
cin >> total_marks;
percentageoutput = obtain_marks * 100 / total_marks;
cout << "percentage is " << percentageoutput <<endl;
}
void grade(){
int percentage;
cout << "Enter your percentage"<<endl;
cin >> percentage;
if(percentage >= 90){
cout << "you got grade A+"<<endl;
}else if(percentage >= 80){
cout << "you got grade A"<<endl;
}else if(percentage >= 50){
cout << "you got grade b"<<endl;
}else if(percentage >= 33){
cout << "you are passed"<<endl;
}else{
cout << "your are failed"<<endl;
}
}
void average(){
int sum = 0;
int items[4];
int average_calculate;
cout << "Enter four items price"<<endl;
for(int i = 0; i < 4; i++){
cin >> items[i];
}
for(int i = 0; i < 4; i++){
sum += items[i];
average_calculate = sum / 4;
}
cout << "items average is " << average_calculate <<endl;
}
main(){
int choice;
char ch;
do{
cout << "Calculators"<<endl;
cout << "press 1 to calculate percentage"<<endl;
cout << "press 2 to calculate grade " <<endl;
cout << "press 3 to calculate average" <<endl;
cout << "press 4 to exit" <<endl;
cout << "Enter your choice"<<endl;
cin >> choice;
switch(choice){
case 1:
percentage();
break;
case 2:
grade();
break;
case 3:
average();
break;
case 4:
exit(0);
break;
default:
cout << "invalid input" <<endl;
}
cout << "press Y or y to continue"<<endl;
cin >> ch;
}while(ch == 'Y' || ch == 'y');
}
No comments:
Post a Comment