Sunday, January 24, 2010

Task 3: Leap year

Now let’s try to make this task.
Make a program to determine whether a year is a leap year or not

Answer:

#include
#include
main()
{
int y;
cout<<"Enter a year: ";
cin>>y;
if (y%4==0)
{cout<<"Leap Year";}
else
{cout<<"Not Leap Year";}
getch();
}

Look at these pictures:




Note:
A leap year is a year that can be divided by 4.
That is mean that the rest of the year divided by for is 0.
In the formula we need to use %. It is the symbol of mod (modulus).
It is used to calculate the rest of divide operation.
For example:
5 % 2 = 1
11 % 4 = 3

Read More..

Saturday, January 23, 2010

Task 2: Salary tax

Let's do the second task.
Make a program to determine whether you have to pay a tax or not according to your salary.
( in Indonesia, you have to pay salary tax if your minimum salary in a year is Rp 15.600.000,-)

Answer:
#include “iostream.h”
#include “conio.h”
main(){
int salary;

cout<<"Enter your salary per month: Rp."; cin>>salary;
if (salary<=0)
{cout<<"Do you mean that you area jobless?";}
else if ((salary*12)>=15600000)
{cout<<"You have to pay a tax";}
else
{cout<<"You may not pay a tax";}
getch();

}

Look at these picture below:





Read More..

Friday, January 22, 2010

Task 1: solid, liquid or gas

Now is the correct time to do some task, because there are enough lessons posted before.
The task will be posted from this post until some following post.

Let’s begin.
Task 1:
Make a program, to decide whether the water is in form of solid (ice) or liquid or gas, according to the temperature.

Answer:
#include "iostream.h"
#include "conio.h"

main()
{
int temp;
cout<< "Form of Water";
cout<< "\n\nEnter the temperature (in celcious): ";
cin>>temp;
if (temp< 0)
cout<<"Solid";
else if (temp< 100)
cout<< "Liquid";
else
cout<< "Gas";
getch();
}

See the picture below as the result:
1. When a negative number was entered


2. When a number from 0 and 99 was entered


3. When number 100 or higher




Read More..