101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Simple calculator 2
DESCRIPTION: Simple calculator 2
Submitted: 09-Apr-2008 10:14:10 ( 38w 5d 20h ago ) Language: C++ (*.cpp *.h)
Views: 107 Lines of Code: 87 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Beginner
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Simple calculator 2
   History: 
*/



#include<stdio.h>
#include<math.h>

main()
{
  int x,y,ans,i;
  int choice;
  float div;
  char loop;
  ans=0;

  clrscr();

  do
  {
      printf("\n Do you wish to continue (Y/N) : ");
      scanf("%s",&loop);

      if (loop=='y' || loop=='Y')
      {
      clrscr();
      printf("\n Enter any two numbers ");
      printf("\n --------------------- ");

      printf("\n\n Enter the first number : ");
      scanf("%d",&x);

    printf("\n Enter the second number : ");
     scanf("%d",&y);

     clrscr();
     printf("\n Select the operation to be carried out ");
     printf("\n -------------------------------------- ");

     printf("\n 1. Addition ");
     printf("\n 2. Substraction ");
     printf("\n 3. Multiplication ");
     printf("\n 4. Division ");

     printf("\n Enter your choice : ");
     scanf("%d",&choice);

  switch(choice)
  {
     case 1 :
     {
	   ans = x+y;
	   printf("\n Answer = %d",ans);
	   break;
     }
     case 2 :
     {
	      ans = x-y;
	      printf("\n Answer = %d", ans);
	      break;
     }
     case 3 :
     {
	      ans = x*y;
	      printf("\n Answer = %d", ans);
	      break;
     }
     case 4:
     {
	      div = x/y;
	      printf("\n Answer = %.2f", div);
	      break;
     }
     default:
	   printf("\n\n Illegal operation......");
	   break;
   }
  }
  else
      printf("\n Bye....... Bye...........");
      getch();
 }while(loop=='y' || loop=='Y');
}