View Single Post
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: CIN>>EQUATION (how to then mult by it later)

 
0
  #7
Nov 5th, 2008
Sounds like your trying to parse a function. You'll have to enter the function as a string (either char * or string class), then use a loop to figuire out its contents. Depending on how robust/useful you want it to be, this could be a bit challenging for a beginner. Here's a start:

  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. string sFormula = "";
  7. strin sBuffer = "";
  8. bool numStream(false);
  9. int iVal[255] = {0};
  10. int iCount(0);
  11. cout << "Enter formula: ";
  12. cin >> sFormula
  13. for (int i(0); i < strlen(sFormula); ++i)
  14. {
  15. if (isdigit(sFormula[i]))
  16. {
  17. numStream = true;
  18. sBuffer += sFormula[i];
  19. }
  20. if (numStream && !isdigit(sFormula[i])
  21. {
  22. numStream = false;
  23. iVal[iCount++] = atoi(sBuffer);
  24. }
  25. }
  26. return 0;
  27. }

This will parse the formula and extract all the numbers into an array. This isn't really useful for solving anything, but it's a start. I would sugguest creating a class for holding/handling formulas and their operations. As you can see, it's a bit more complex an issue than it seems
Last edited by skatamatic; Nov 5th, 2008 at 3:15 pm.
Reply With Quote