Hello there! Would you, please, help me to find a mistake in a small piece of my code for this easy task? Here is my code:

#include <bits/stdc++.h>

    using namespace std;

int main() {
    int t, k, num, arr[3];
    string s, number;
    cin >> t;
    cin.ignore();
    for (int i = 0; i < t; i++) {
        cout << "\n";
        getline(cin, s);
        stringstream str(s);
        k = 0;
        while (str >> number) {
            if (number != "+" && number != "=") {
                if (number.find("machula") != string::npos) num = k;
                arr[k] = atoi(number.c_str());
                k++;
            }
        }
        if (num == 0) arr[0] = arr[2] - arr[1];
        else if (num == 1) arr[1] = arr[2] - arr[0];
        else arr[2] = arr[0] + arr[1];
        cout << arr[0] << " + " << arr[1] << " = " << arr[2] << "\n";
    }
    system("pause");
    return 0;
}
  • created

    Jul '18
  • last reply

    Jul '18
  • 1

    reply

  • 723

    views

  • 1

    user

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 25 16d

Want to read more? Browse other topics in C and C++ or view latest topics.