Saturday, October 17, 2015

Well explained Program to make a calculator C++

In this post we will create a simple calculator in our program today. The user will enter the first value then he will give the arithmetic operator and then he will give the second value. The compiler will then give the answer against the arithmetic operators, in this program we will learn little bit about TEXT data types.

The complete code of this program is as follows:

#include <iostream>
using namespace std;
int main (void)
{
         int a, b,c ;
         char op;
         
         
         cout << "Enetr the value" <<"\n";  

        cin >> a ;
        cout << "Enter the other value" <<"\n";
        cin >> b; 
        cout << "Enter arethmetic operation" <<"\n";
        cin >> op;
        if (op == '+')
        {cout << a + b;
          }
          
          if (op == '-')
         { cout << a - b;
          }
          
          
          if ( op == '/')
         { cout << a / b;
          }
          
          if ( op == '*')
          {cout << a * b;
          }
          
                      
       system ("pause");
       return 0;
    
 
}

Wednesday, October 14, 2015

Well explained Program to display a table C++

In this program we'll be looking at loops (for loop) and discuss a sample program in detail to understand how it works. The code of the program which we'll look at today is given below.

#include <iostream>
using namespace std;
int main (void)
{
    
    
    int a,b ;
    cin >> b;
    
    for ( a =1;  a <=10; a++ )    
    {
               cout << b <<"x" <<  a << "=" << (b * a) << "\n" ;
                     
                     }
        
        
    system("pause");
    return 0;
}

Monday, October 12, 2015

Learning C++ Breaking down a simple program

We'll dissect a simple program made in C++ today. This program asks user for an input and then tells whether the number is even or odd.

The complete code for an even odd detection program is here

#include <iostream>
using namespace std;

int main()
{
   int a;
   cout<<"Please enter a number"<<"\n";
   cin>>a;
   if (a % 2 ==0)
   {
      cout <<" The number is even" <<"\n";
   }
   else
   {
      cout <<" The number is odd" <<"\n";
   }
   system("pause");
   return 0;
}