Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- fail:
- int x = 0,y = 0;
- char o;
- cout <<"Enter two numbers => ";
- cin >>x>>o>>y;
- while(true)
- {
- if(cin.fail())
- {
- cout <<"Error : you are entered a character value ! ..."<<"\n";
- cin.clear();
- string il;
- getline(cin, il);
- goto fail;
- }
- else if(o=='+')
- {
- cout <<"result = "<<x+y<<"\n";
- break;
- }
- else if(o=='-')
- {
- cout <<"result = "<<x-y<<"\n";
- break;
- }
- else if(o=='*')
- {
- cout <<"result = "<<x*y<<"\n";
- break;
- }
- else if(o=='/')
- {
- cout <<"result = "<<x/y<<"\n";
- break;
- }
- else if(o=='%')
- {
- cout <<"result = "<<x%y<<"\n";
- break;
- }
- else
- {
- cout <<"invalid operation ! ..."<<"\n";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement