problem:my little app of calculation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <sstream>
using namespace std;


void cutstring(string & p,int &pos,double & opd1,double & opd2)
{
      stringstream ss(p.substr(0,pos));
      cout<<"\n this is just a debug information."
       <<"\n to show the position of the iterator"
       <<"\n the position is "<<pos<<"\n";
     ss>>opd1;
     cout<<"the opd1 is "<<opd1<<"\t";
     stringstream xx(p.substr(pos+1,p.length()-pos));
      xx>>opd2;
     cout<<"the opd2 is "<<opd2<<'\n';
     }


int main()
{
    
    //my calculator
    double opd1,opd2;
    string uript;
   
    int temp;
    cout<<"input ur expression. (note if u input \"quit\", u will quit)"<<endl;
  while (1)
    {
        temp=0;uript="";opd1=0;opd2=0;
        cout<<"loop starts"<<endl;
        cin>>uript;
     if ((temp=uript.find_first_of('+',0))!=string::npos)
             { 
                   cout<<"\n !!!debug!!! iterator is "<<temp<<endl;
                              cout<<"u entered the + program\n";
                              cutstring(uript,temp,opd1,opd2);
               cout<<"result\t"<<(opd1+opd2)<<endl;}
        else if (temp=uript.find_first_of('-',0)!=string::npos)
        {
             cout<<"\n !!!debug!!! iterator is "<<temp<<endl;
               cout<<"u entered the - program\n";
             cutstring(uript,temp,opd1,opd2);
               cout<<"result\t"<<(opd1-opd2)<<endl;}
           else if (temp=uript.find_first_of('*',0)!=string::npos)
              {
                   cout<<"\n !!!debug!!! iterator is "<<temp<<endl;
                     cout<<"u entered the * program\n";
                   cutstring(uript,temp,opd1,opd2);
               cout<<"result\t"<<(opd1*opd2)<<endl;}
             else if (temp=uript.find_first_of('/',0)!=string::npos)
                  {
                                                                  cout<<"\n !!!debug!!! iterator is "<<temp<<endl;
                                             cout<<"u entered the / program\n";
                                           cutstring(uript,temp,opd1,opd2);
               cout<<"result\t"<<(opd1/opd2)<<endl;}
               else if (uript=="quit")
                   break;
               else 
                   {cout<<"ur input is not correct. please try again."; continue;}
}
    cout<<endl<<"hope u have a nice day ^.^";

    }


shown above. i got the problem that it sometimes doesn't show the correct 'iterator'(i don't know whether my notion is right?). Just that variable "temp". Could u help me correct the mistake?
The function of the program is that shows the result after operation like "+,-,*,/". the variables are taken from the string. the problem in it i think is just about the string process. Thx in advance.
Topic archived. No new replies allowed.