Haval1

true

Oct 28th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. // TrueFalseFinal.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. void equation(string x, string &a, string &b, string &c, char &op) {
  10.     int aa = 0, bb = 0, cc = 0, j = 0, k = 0, l = 0;
  11.  
  12.     // first
  13.     while (x[aa] != op)
  14.     {
  15.         aa++;
  16.     }
  17.  
  18.     while (x[bb] != '=')
  19.     {
  20.         bb++;
  21.     }
  22.  
  23.     for (int i = 0; i < aa; i++)
  24.     {
  25.         a[j] = x[i];
  26.         j++;
  27.     }
  28.  
  29.     for (int i = aa + 1; i < bb; i++)
  30.     {
  31.         b[k] = x[i];
  32.         k++;
  33.     }
  34.  
  35.     for (int i = bb + 1; i < x.length(); i++)
  36.     {
  37.         c[l] = x[i];
  38.         l++;
  39.     }
  40. }
  41.  
  42. void check(string a, string b, string c, char op)
  43. {
  44.     float n = 0, m = 0, z = 0;
  45.     if (isdigit(a[0]) && isdigit(b[0]) && isdigit(c[0]))
  46.     {
  47.         n = stoi(a);
  48.         m = stoi(b);
  49.         z = stoi(c);
  50.  
  51.         if (op == '+')
  52.         {
  53.             if (n + m == z)
  54.                 cout << "\nTRUE\n";
  55.         }
  56.         if (op == '-')
  57.         {
  58.             if (n - m == z)
  59.                 cout << "\nTRUE\n";
  60.         }
  61.         if (op == '*')
  62.         {
  63.             if (n * m == z)
  64.                 cout << "\nTRUE\n";
  65.         }
  66.         if (op == '/')
  67.         {
  68.             if (n / m == z && m != 0)
  69.                 cout << "\nTRUE\n";
  70.             if (m == 0)
  71.                 cout << "\nFALSE\n";
  72.         }
  73.     }//end if all digit
  74.  
  75.     else
  76.         cout << "\nFALSE\n";
  77. }
  78. int main()
  79. {
  80.     string x, a, b, c;
  81.  
  82.     getline(cin, x);
  83.     char op;
  84.  
  85.     for (int i = 0; i < x.length(); i++)
  86.     {
  87.         if (x[i] == '+' || x[i] == '-' || x[i] == '*' || x[i] == '/')
  88.             op = x[i];
  89.     }
  90.  
  91.     int d = x.size();
  92.     a.resize(d);
  93.     b.resize(d);
  94.     c.resize(d);
  95.  
  96.     equation(x, a, b, c, op);
  97.  
  98.     check(a, b, c, op);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment