Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- float n1 = 0.0F;
- float n2 = 0.0F;
- float ans = 0.0F;
- char ch = '\0'; //NULL
- cout<<"Calculator App"<<endl;
- cout<<"===================="<<endl;
- cout<<"Please enter first number: ";
- cin>>n1;
- cout<<"Please enter second number: ";
- cin>>n2;
- cout<<"choose operation +,-,*,/,%: ";
- cin>>ch;
- if (ch == '+'){
- ans = n1 + n2;
- }
- else if (ch == '-'){
- ans = n1 - n2;
- }
- else if (ch == '*'){
- ans = n1 * n2;
- }
- else if (ch == '/'){
- ans = n1 / n2;
- }
- else if (ch == '%'){
- ans = (int)n1 % (int)n2;
- }
- else {
- cout << "Invalid operation!" << endl;
- return 1; // Exit with error code
- }
- cout<<"answer = "<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement