Do you have a program that calculates C ++ system? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Do you have a program that calculates C ++ system?

ex)4+5*12+6/20

6th Apr 2018, 9:42 AM
권진
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.
6th Apr 2018, 10:19 AM
Timon Paßlick
0
Please explain us what you mean, it's not clear to us.
6th Apr 2018, 10:10 AM
Timon Paßlick
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
6th Apr 2018, 10:16 AM
권진