Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string SpaceRemoval(string & EquationText)
- {
- string NewEquationText = "";
- // check every character
- for (int i = 0; i < EquationText.length(); i++)
- {
- if (EquationText[i] != ' ') // if the character is not a ' ' then add it to the NewEquationText
- {
- NewEquationText += EquationText[i];
- }
- }
- // return the NewEquationText
- return NewEquationText;
- }
- second part
- bool GetEquation()
- {
- // Input equation
- cout << "Equation F(x) = ";
- cin >> EquationText;
- // Add Parentheses in the equation
- AddParentheses(EquationText);
- // Remove extra spaces in the equation
- EquationText = SpaceRemoval(EquationText);
- // Check if the equation is valid
- return EquationValidation(EquationText);
- }
- final part
- #include "Header.h"
- int main()
- {
- while(true)
- {
- // Get Equation
- if (GetEquation())
- {
- // it's a valid equation
- calculateExpression(EquationText)
- }
- else
- {
- // it's a invalid equation
- cout << "invalid equationnn";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement