The value of the term - the solution
#include <iostream>
#include<string>
using namespace std;
int main()
{
string iz,s1,s2;
getline( cin, iz );
int poz[4];
//Returns the position of the computational operation or -1 if it is not found
poz[0]=iz.find("+");
poz[1]=iz.find("-");
poz[2]=iz.find("*");
poz[3]=iz.find("/");
int i=0, p, q;
while(poz[ i ]==-1){
i++;
}
q=i;
p=poz[i];
//numbers in the form of a string
s1=iz.substr(0,p);
s2=iz.substr(p+1);
//Convert numbers to int data
int a=0, b=0;
for(int i=0;i<s1.length();i++){
char ch= s1.at(i); //character from the string at the i-th position, eg. ch = 3
int c=ch-'0'; // c= '3' - '0', the difference of the codes of these digits is 3
a=10*a+c;
}
for(int i=0;i<s2.length();i++){
char ch= s2.at(i);
int c=ch-'0';
b=10*b+c;
}
switch(q){ //selection of the switch based on the value of the integer variable q, which represents
case 0: cout<<a+b<<endl; break; //calculation operation
case 1: cout<<a-b<<endl; break;
case 2: cout<<a*b<<endl; break;
case 3: cout<<a/b<<endl;
}
return 0;
}
#include<string>
using namespace std;
int main()
{
string iz,s1,s2;
getline( cin, iz );
int poz[4];
//Returns the position of the computational operation or -1 if it is not found
poz[0]=iz.find("+");
poz[1]=iz.find("-");
poz[2]=iz.find("*");
poz[3]=iz.find("/");
int i=0, p, q;
while(poz[ i ]==-1){
i++;
}
q=i;
p=poz[i];
//numbers in the form of a string
s1=iz.substr(0,p);
s2=iz.substr(p+1);
//Convert numbers to int data
int a=0, b=0;
for(int i=0;i<s1.length();i++){
char ch= s1.at(i); //character from the string at the i-th position, eg. ch = 3
int c=ch-'0'; // c= '3' - '0', the difference of the codes of these digits is 3
a=10*a+c;
}
for(int i=0;i<s2.length();i++){
char ch= s2.at(i);
int c=ch-'0';
b=10*b+c;
}
switch(q){ //selection of the switch based on the value of the integer variable q, which represents
case 0: cout<<a+b<<endl; break; //calculation operation
case 1: cout<<a-b<<endl; break;
case 2: cout<<a*b<<endl; break;
case 3: cout<<a/b<<endl;
}
return 0;
}