Advertisement
sidex15

2/14/2019 C++ exercise #2

Feb 14th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. int main()
  6. {
  7. int a;
  8. char d[100];
  9. X:clrscr();
  10. cout<<"enter a string: ";
  11. cin>>d;
  12.  a=strlen(d);
  13.  if(d[0]=='('&&d[1]=='('){
  14.   if(d[a-1]==')'&&d[a-2]==')'){
  15.    cout<<"valid";
  16.    getch();
  17.    goto X;
  18.   }
  19.   else{
  20.     cout<<"invalid";
  21.     getch();
  22.     goto X;
  23.    }
  24.   }
  25.  else if(d[0]=='['&&d[1]=='['){
  26.   if(d[a-1]==']'&&d[a-2]==']'){
  27.    cout<<"valid";
  28.    getch();
  29.    goto X;
  30.    }
  31.    else{
  32.     cout<<"invalid";
  33.     getch();
  34.     goto X;
  35.    }
  36.   }
  37.  else if(d[0]=='{'&&d[1]=='{'){
  38.   if(d[a-1]=='}'&&d[a-2]=='}'){
  39.    cout<<"valid";
  40.    getch();
  41.    goto X;
  42.    }
  43.    else{
  44.     cout<<"invalid";
  45.     getch();
  46.     goto X;
  47.    }
  48.   }
  49.   else if(!strcmp(d,"exit")){
  50.     exit(0);
  51.    }
  52.   else{
  53.    cout<<"invalid";
  54.    getch();
  55.    goto X;
  56.   }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement