Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string>
- #include <string.h>
- #define print(var) cout << #var << ": " << var << endl;
- using namespace std;
- string solve(int a, char o, int b, int r);
- int main() {
- int a, b, r;
- char op = '+';
- string input;
- while ( (cin >> input) && input != "") {
- //sscanf(sentence, "%s %*s %d", str, &i);
- if (input.find('+') != -1) {
- input.at(input.find('+')) = ' ';
- op = '+';
- }
- else if (input.find('-') != -1) {
- input.at(input.find('-')) = ' ';
- op = '-';
- }
- else if (input.find('x') != -1) {
- input.at(input.find('x')) = ' ';
- op = '*';
- }
- else {
- input.at(input.find(':')) = ' ';
- op = ':';
- }
- sscanf(input.c_str(), "%d %d=%d", &a, &b, &r);
- cout << solve(a, op, b, r) << endl;
- }
- }
- string solve(int a, char o,int b, int r) {
- double result = 0.0;
- switch (o)
- {
- case '+':
- result = a + b;
- break;
- case '-':
- result = a - b;
- break;
- case '*':
- result = double(a) * b;
- break;
- case ':':
- result = double(a) / b;
- break;
- }
- return result == r ? "Correct" : "Incorrect";
- }
Advertisement
Add Comment
Please, Sign In to add comment