Sunday, 13 January 2013

Calculator coded in C++


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
 int a,b;
 char opr;
 textmode(C80);
 clrscr();
  textbackground(BLACK);
  textcolor(WHITE+BLINK);
  gotoxy(10,1);
  textbackground(BLACK);
  cprintf("CALCULATOR");
  textcolor(WHITE);
 label:
 gotoxy(9,3);
 cout<<"Enter number here ";
 putchar(25);
 gotoxy(27,4);
 cin>>a;
 gotoxy(27,5);
 cin>>b;
 gotoxy(15,10);
 cout<<"[+][-][*]    [CE]";
 gotoxy(15,11);
 cout<<"[\/][  = ]";
 gotoxy(15,13);
 cout<<"Select operator: ";
 opr=getch();
 gotoxy(25,5);
 putchar(opr);
 gotoxy(25,6);
 cout<<"----------";
 textbackground(BLACK);
 gotoxy(18,11);
 textbackground(GREEN);
 cprintf("[  = ]");
 textcolor(WHITE);
 switch(opr)
 {
  case '+':
  textbackground(BLACK);
  gotoxy(15,10);
  textbackground(YELLOW);
  cprintf("[+]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a+b;
  break;
  case '-':
  textbackground(BLACK);
  gotoxy(18,10);
  textbackground(YELLOW);
  cprintf("[-]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a-b;
  break;
  case '*':
  textbackground(BLACK);
  gotoxy(21,10);
  textbackground(YELLOW);
  cprintf("[*]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a*b;
  break;
  case '/':
  textbackground(BLACK);
  gotoxy(15,11);
  textbackground(YELLOW);
  cprintf("[\/]");
  textcolor(WHITE);
  gotoxy(25,7);
  cout<<"="<<a/b;
  break;
  case 'c':
  case 'C':
  textbackground(BLACK);
  gotoxy(28,10);
  textbackground(YELLOW);
  cprintf("[CE]");
  textcolor(WHITE);
  gotoxy(25,7)
  goto label;
  default:
  gotoxy(27,4);
  cout<<"    ";
  gotoxy(27,5);
  cout<<"    ";
  gotoxy(25,7);
  cout<<"         ";
  cout<<"Invalid operator.";
  break;
 }
 getch();
}

No comments:

Post a Comment