Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- float pot (float a, float b)
- {
- int i = 0;
- float pow = a;
- for (i = 1; i < (int) b; i++)
- pow = pow * a;
- return pow;
- }
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int main()
- {
- float n1 = 0, n2 = 0, r = 0;
- char c;
- int ctr = 0;
- printf("Simple calculator by andreafiori\n");
- do
- {
- cin >> n1;
- cin >> c;
- cin >> n2;
- switch (c)
- {
- case '+' :
- r = n1 + n2;
- break;
- case '-' :
- r = n1 - n2;
- break;
- case '*' :
- r = n1 * n2;
- break;
- case '^' :
- r = pot (n1, n2);
- break;
- case '/' :
- if (n2 == 0)
- printf("The value is not valid!\n");
- else
- r = n1 / n2;
- break;
- default :
- printf("The operation is not allowed!\n");
- break;
- }
- printf (" = %f\nRepeat ? [1 = yes/ 0 = no] ", r);
- scanf ("%d", &ctr);
- } while (ctr == 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement