#include #include #include #include #include using namespace std; bool checkInput(string input); double computeFirst(int valx,int valn); double computeMid(int valx,int valn); double computeLast(int valx,int valn); double factorial(int value); int conValues(double input); //convert double value to integer void displayRules(); int main() { string inputx, inputn, confirm, name,rules; int n,x,error,ignore=1; long double First,Middle,Last,Final; bool contd,digitx, digitn; cout << "***************************" << endl; cout << "* Assignement 2 *" << endl; cout << "***************************" << endl; cout << "Do you look at the rules? (Y/N) " << endl; cin >> rules; cin.ignore(); if(rules == "y" || rules == "Y") displayRules(); do{ //ask whether the user continue playing or not do{ error = 1; //reset & default cout << endl; cout << "Please enter the value of x" << endl; getline(cin,inputx); cout << "Please enter the value of n" << endl; getline(cin,inputn); if(inputn == "" || inputx == "") error = 5; //null inputs else{ digitx = checkInput(inputx); digitn = checkInput(inputn);} if(error == 5){ cout << "No inputs are entered, please enter again.\n"; contd = false;} else if(digitx && digitn){ x = atoi(inputx.c_str()); //convert x n = atoi(inputn.c_str()); //convert n if(n<1) error = 2; // n must be greater than 1 else if (x == 0) error = 3; // x cannot equal to 0 else error = 1;} //everything fine when contd = 1 else{ x = atoi(inputx.c_str()); //convert x n = atoi(inputn.c_str()); //convert n error = 4;} //input contain invalid char if(error == 1){ // no errors cout << "The converted value of x is " << x << endl; cout << "The converted value of n is " << n << endl; contd = true; if(x>200 || n>200){ cout << "Input values are too big.This might affect the accuracy of the answers.\n"; cout << "It is recommended to input the values smaller than 100." <> confirm; cin.ignore(); if(confirm == "y" || confirm == "Y") contd = true; //cofirm values else if (confirm == "N" ||confirm == "n") contd = false; //not confirm values else //user enter invalid values cout << "Invalid input.Please enter again" <> confirm; cin.ignore(); if(confirm == "y" || confirm == "Y") contd = true; else if (confirm == "N" ||confirm == "n") contd = false; else //user enter invalid values cout << "Invalid input.Please enter again" <> name; cout << "\n-------------------------- THE END --------------------------" << endl; cout << "\nThank you, Mr/Ms " << name << " for spending time on this program" << endl <