Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- float a, b, cnt = 3;
- int c, d;
- float sum = 0;
- cout << "Simple calculator" << endl;
- cout << "1 number:";
- cin >> a;
- cout << "2 number:";
- cin >> b;
- cout << "How to calculate?" << endl;
- again:
- cout << "1:+ 2:- 3:× 4:÷" << endl;
- cin >> c;
- if (c == 1)
- {
- sum = a + b;
- cout << a << "+" << b << "=" << sum << endl;
- }
- else if (c == 2)
- {
- sum = a - b;
- cout << a << "-" << b << "=" << sum << endl;
- }
- else if (c == 3)
- {
- sum = a * b;
- cout << a << "×" << b << "=" << sum << endl;
- }
- else if (c == 4)
- {
- sum = a / b;
- cout << a << "÷" << b << "=" << sum << endl;
- }
- else
- {
- cout << "An unexpected error occurred" << endl;
- cout << "Please re-enter the calculate method" << endl;
- goto again;
- }
- c = 0;
- while (1)
- {
- cout << cnt << " nember:";
- cin >> d;
- cout << "How to calculate?" << endl;
- again1:
- cout << "1:+ 2:- 3:× 4:÷" << endl;
- cin >> c;
- if (c == 1)
- {
- sum = sum + d;
- cout << sum - d << "+" << d << "=" << sum << endl;
- }
- else if (c == 2)
- {
- sum = sum - d;
- cout << sum << "-" << d << "=" << sum << endl;
- }
- else if (c == 3)
- {
- sum = sum * d;
- cout << sum << "×" << d << "=" << sum << endl;
- }
- else if (c == 4)
- {
- sum = sum / d;
- cout << sum << "÷" << d << "=" << sum << endl;
- }
- else
- {
- cout << "An unexpected error occurred" << endl;
- cout << "Please re-enter the calculate method" << endl;
- goto again1;
- }
- cnt++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement