Thursday, 18 July 2013


#include "stdafx.h"
#include "conio.h"
#include "iostream"
#include "stdio.h"

using namespace std;

void AddNumber();
void AddIntegerNumer();
void AddRealNumber();
void AddCharNumber();
void SubtractNumber();
void MultiplyNumber();
void DivideNumber();
void ModulusNumber();


int _tmain(int argc, _TCHAR* argv[])
{
       char choice;
       char option;

       do
       {
              cout<<"press + to add two numbers"<<endl;
              cout<<"press - to subtract two numbers"<<endl;
              cout<<"press * to multiply two numbers"<<endl;
              cout<<"press / to divide two numbers"<<endl;
              cout<<"press % to take modulus of two numbers"<<endl;
              cout<<"press # for exit"<<endl;
              cout<<"enter your choice"<<endl;
              cin>>choice;

              switch(choice)
              {
              case '+':
                           {
                           int choice;
                           do
                           {
                                  cout<<"press 1 for integer nubmer addition"<<endl;
                    cout<<"press 2 for real number addition"<<endl;
                                  cout<<"press 3 for char number addition"<<endl;
                                  cout<<"press 4 for exit"<<endl;
                                  cout<<"enter your choice"<<endl;
                                  cin>>choice;

                                  switch(choice)
                                  {
                                  case 1:
                                         AddIntegerNumer();
                                         break;
                                  case 2:
                                         AddRealNumber();
                                         break;
                                  case 3:
                                         AddCharNumber();
                                         break;
                                  case 4:
                                         exit(0);
                                  default:
                                         cout<<"nothing match"<<endl;

                                  }
                                  cout<<"would you like to continue? press y or Y";
                                  cin>>option;
              }while(option=='y'||option=='Y');
                                 
                     }
                     break;
              case '-':
                     SubtractNumber();
                     break;
              case '*':
                     MultiplyNumber();
                     break;
              case '/':
                     DivideNumber();
                     break;
              case '%':
                     ModulusNumber();
                     break;
              case '#':
                     exit(0);
              default:
                     cout<<"nothing match"<<endl;
              }

                     cout<<"would you like to continue? press y or Y";
                     cin>>option;
              }while(option=='y'||option=='Y');
      
       getch();

}

void AddIntegerNumer()
{
       int n1,n2;
       int sum=0;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       sum=n1+n2;
       cout<<"sum="<<sum<<endl;
}

void AddRealNumber()
{
       int n1,n2;
       int sum=0;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       sum=n1+n2;
       cout<<"sum="<<sum<<endl;
}

void AddCharNumber()
{
       char ch1,ch2;
       int sum=0;
       cout<<"enter ch1 and ch2"<<endl;
       cin>>ch1>>ch2;
       sum=ch1+ch2;
       cout<<"sum="<<sum<<endl;
}

void SubtractNumber()

{
       int n1,n2;
       int subtract=0;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       subtract=n1-n2;
       cout<<"subtract="<<subtract<<endl;
}

void MultiplyNumber()
{
       int n1,n2;
       int multiply;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       multiply=n1*n2;
       cout<<"multiply="<<multiply<<endl;
}
void DivideNumber()
{
       int n1,n2;
       int division;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       division=n1/n2;
       cout<<"division="<<division<<endl;
}

void ModulusNumber()
{
       int n1,n2;
       int modulus;
       cout<<"enter n1 and n2"<<endl;
       cin>>n1>>n2;
       modulus=n1/n2;
       cout<<"modulus="<<modulus<<endl;

}
Reactions:

0 comments :

Post a Comment