hi, i am using DEV-C++ and i have two problems with this code:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main (char argc)
{
string n1;
getline(cin,n1);
int len;
len = n1.length();
int len1 = -2;
int len2 = -1;
for(int t = len; t>0; t--)
{
len1 = len1 + 2;
len2 = len2 + 2;
cout << "number "<< n1[len1] << endl;
cout << "operator "<< n1[len2] << endl;
}
system("pause");
}
i want the output to never end with an operator and whenever i enter a number larger than 9, it ends with an operator. my second problem is after i enter an equation (like 1+1), the output is 1+1 and then it outputs just some weird gibberish. and here i have some other code:
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main (char argc)
{
string n1;
getline(cin,n1);
int len;
len = n1.length();
int len1 = -2;
int len2 = -1;
for(int t = len; t>0; t--)
{
len1 = len1 + 2;
len2 = len2 + 2;
cout << "number "<< n1[len1] << endl;
cout << "operator "<< n1[len2] << endl;
if(n1[len2] == "+")
{
cout << n1[len1] + n1[len1] << endl;
} //didnt want to put "-,/,*" yet
}
system("pause");
}
and the problem with this code is that i keep getting this error 25 F:\random\test.cpp ISO C++ forbids comparison between pointer and integer. any solutions?