Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int calc(float *num_1, float *num_2, char *b) {
- float result;
- if (*b == '/') {
- result = *num_1 / *num_2;
- cout << *num_1 << "/" << *num_2 << "=" << result << endl;
- return 0;
- }
- if (*b == '+') {
- result = *num_1 + *num_2;
- cout << *num_1 << "+" << *num_2 << "=" << result << endl;
- return 0;
- }
- if (*b == '*') {
- result = *num_1 * *num_2;
- cout << *num_1 << "*" << *num_2 << "=" << result << endl;
- return 0;
- }
- if (*b == '-') {
- result = *num_1 - *num_2;
- cout << *num_1 << "-" << *num_2 << "=" << result << endl;
- return 0;
- }
- }
- int main(int argc, const char * argv[]) {
- float num_1;
- float num_2;
- char b;
- cin >> num_1;
- cin >> b;
- cin >> num_2;
- /if (((num_1 <= 0 || num_1 >= 0) && (num_2 <= 0 || num_2 >= 0) && (b == '+' || b == '*' || b == '%' || b == '-' || b == '/'))) {
- }
- else {
- cout << "You specified an incorrect action!" << endl;
- }
- if (b == '/' && num_2 == 0) {
- cout << "Error, can not divide by zero!" << endl;
- }
- else {
- calc(num_1, num_2, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement