Friday, November 30, 2012

Program C++ Tutorial 9 : Calculator

Hello ! everybody, in this Tutorial 9 I'd like to make simple program Calculator by use C++ language and below is Video and source code for make it.

Source Code :

/*
Name : Phirum Tan
NIM  : 49012082
Major: TMD
*/
#include <iostream>
using namespace std;
float multi(float x , float y)
{
float result;
result = x * y ;
return result;
};
float addi(float x ,float y)
{
float result;
result = x + y ;
return result;
};
float sub(float x , float y)
{
float result;
result = x - y;
return result;
};
float divide(float x ,float y)
{
float result;
result = x / y;
return result;
};
int main()
{
int i;
float a , b , show;
cout << "This is Simple program calculator."
<< endl;
cout << "Press number 1 for Multi."
<< endl;
cout << "Press number 2 for Addition."
<< endl;
cout << "Press number 3 for Minus"
<< endl;
cout << "Press number 4 for Divide."
<< endl;
cin >> i;
switch(i)
{
case 1 :
{
cout << "Value 1 = "
<< endl;
cin >> a;
cout << "Value 2 = "
<< endl;
cin >> b;
show = multi(a,b);
cout << "Result = "
<< show
<< endl;
break;
}
case 2:
{
cout << "Value 1 = "
<< endl;
cin >> a;
cout << "Value 2 = "
<< endl;
cin >> b;
show = addi(a,b);
cout << "Result = "
<< show
<< endl;
break;
}
case 3:
{
cout << "Value 1 = "
<< endl;
cin >> a;
cout << "Value 2 = "
<< endl;
cin >> b;
show = sub(a,b);
cout << "Result = "
<< show
<< endl;
break;
}
case 4:
{
cout << "Value 1 = "
<< endl;
cin >> a;
cout << "Value 2 = "
<< endl;
cin >> b;
show = divide(a,b);
cout << "Result = "
<< show
<< endl;
break;
}
default :
cout << "Sorry you press wrong."
<< endl;
}
system ("pause");
return 0;
}

Video :

Thanks for watching
Name : Phirum Tan
MIN : 49012082
Major : TMD

No comments:

Post a Comment