Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TrueFalseFinal.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <string>
- using namespace std;
- void equation(string x, string &a, string &b, string &c, char &op) {
- int aa = 0, bb = 0, cc = 0, j = 0, k = 0, l = 0;
- // first
- while (x[aa] != op)
- {
- aa++;
- }
- while (x[bb] != '=')
- {
- bb++;
- }
- for (int i = 0; i < aa; i++)
- {
- a[j] = x[i];
- j++;
- }
- for (int i = aa + 1; i < bb; i++)
- {
- b[k] = x[i];
- k++;
- }
- for (int i = bb + 1; i < x.length(); i++)
- {
- c[l] = x[i];
- l++;
- }
- }
- void check(string a, string b, string c, char op)
- {
- float n = 0, m = 0, z = 0;
- if (isdigit(a[0]) && isdigit(b[0]) && isdigit(c[0]))
- {
- n = stoi(a);
- m = stoi(b);
- z = stoi(c);
- if (op == '+')
- {
- if (n + m == z)
- cout << "\nTRUE\n";
- }
- if (op == '-')
- {
- if (n - m == z)
- cout << "\nTRUE\n";
- }
- if (op == '*')
- {
- if (n * m == z)
- cout << "\nTRUE\n";
- }
- if (op == '/')
- {
- if (n / m == z && m != 0)
- cout << "\nTRUE\n";
- if (m == 0)
- cout << "\nFALSE\n";
- }
- }//end if all digit
- else
- cout << "\nFALSE\n";
- }
- int main()
- {
- string x, a, b, c;
- getline(cin, x);
- char op;
- for (int i = 0; i < x.length(); i++)
- {
- if (x[i] == '+' || x[i] == '-' || x[i] == '*' || x[i] == '/')
- op = x[i];
- }
- int d = x.size();
- a.resize(d);
- b.resize(d);
- c.resize(d);
- equation(x, a, b, c, op);
- check(a, b, c, op);
- }
Advertisement
Add Comment
Please, Sign In to add comment