diff --git a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp index 932f14f..6fdd01e 100644 --- a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp +++ b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp @@ -5,17 +5,22 @@ special right is given to TEAM TYP for educational purpose */ #include #include +#include +#include using namespace std; void calculateGPA(); void calculateCGPA(); void method(); +void inputValidation(int& input, int lowerInputLeveler, int aboveInputLeveler, const string& labelMessage); int main() { system("cls"); int input; + int aboveLabel = 4; + int lowerLabel = 1; cout<<"--------------------------------------------------------------------------"<>input; - switch(input) - { + cout << "Enter your choice: "; + inputValidation(input, lowerLabel, aboveLabel, "Ente your choice"); + switch (input) + { case 1: - calculateGPA(); - break; + calculateGPA(); + break; case 2: - calculateCGPA(); - break; + calculateCGPA(); + break; case 3: - method(); - break; + method(); + break; case 4: - exit(EXIT_SUCCESS); - break; - default: - cout<<"You have entered wrong input.Try again!\n"<::max(); + int lowerGrade = 0; + int aboveGrade = 4; + int lowerCredit = 0; + int aboveCredit = 10; cout<<"-------------- GPA Calculating -----------------"<>q; + inputValidation(q, lowerArraysizePossible, bigArraySizePossible, "how many subject's points do you want to calculate"); - float credit [q]; - float point [q]; + vector credit(q); + vector point(q); cout<>credit[i]; + inputValidation(credit[i], lowerGrade, aboveGrade, "Enter the credit for the subject"); cout<>point[i]; + inputValidation(point[i], lowerGrade, aboveGrade, "Enter the point for the subject"); cout<<"-----------------------------------\n\n"<>inmenu; + inputValidation(inmenu, lowerLabeler, higherLabeler, "Your label input"); switch(inmenu) { @@ -107,27 +114,28 @@ void calculateGPA() break; case 3: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<::max(); + int lowerGradePossible = 0;//(f) + int higherGradePossible = 4;//(A); int l; cout<<"-------------- CGPA Calculating -----------------\n\n"<>l; + inputValidation(l, lowerSemisterSizePossible, higherSemisterSizePossible, "how many semseter results do you want input"); cout<<"\n\n"< semrs(l); int i; for(i=0;i>semrs[i]; + inputValidation(semrs[i], lowerGradePossible, higherGradePossible, "Result CGPA"); cout<<"\n"<>inmenu; + inputValidation(inmenu, lowerLabel, aboveLabel, "your label input"); switch(inmenu) { @@ -158,28 +167,26 @@ void calculateCGPA() break; case 3: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<>inmenu; + inputValidation(inmenu, lowerLabel, aboveLabel, "your label input"); switch(inmenu) { @@ -188,9 +195,23 @@ void method() break; case 2: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<> input) { + if (input >= lowerBound && input <= upperBound) { + break; + } + else { + std::cout << "Please enter a number between " << lowerBound << " and " << upperBound << " (" << labelMessage << ")" << std::endl; + } + } + else { + std::cout << "Invalid input. Please enter a valid number (" << labelMessage << ")" << std::endl; + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + } + } +}