+ 1
Do you have a program that calculates C ++ system?
ex)4+5*12+6/20
4 Answers
+ 1
So you want to build a simple calculator.
Nope, I don't have any code for you.
But you seem good enough to write some on your own.
0
Please explain us what you mean, it's not clear to us.
0
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cout << "7+23+5+100+25." << endl;
getline(cin, s, '\n');
int sum = 0;
int startIndex = 0;
while(true) {
int fIndex = s.find('+', startIndex);
if(fIndex == -1) {Â
string part = s.substr(startIndex);
if(part == "") break;Â
cout << part << endl;
sum += stoi(part);Â
break;
}
int count = fIndex - startIndex;Â
string part = s.substr(startIndex, count);Â
cout << part << endl;
sum += stoi(part);
startIndex = fIndex+1;Â
}
cout << "answer " << sum;
}
this is plus code