Practice Make Perfect!

Hijriyah callendar using function

Posted by: dzikrina on: August 13, 2008

/*USING VARIABLE*/
# include <iostream>
# include <string>
using namespace std;

string numToString (int num);
int main ()
{    int num;
string month;
month = numToString (num);
cout << “Enter a month” << endl;
cin >> num;
cout << num << “Month is ” <<month;

system (“pause”);
return 0;

}
string numToString (int num)
{ string month;
if (num == 1)
month = “Muharram”;

else if (num == 2)
month = “Safar”;

else if (num == 3)
month = “Rabiul Awal”;

else if (num == 4)
month = “Rabiul Tsani”;

else if (num == 5)
month = “Jumadil Awal”;

else if (num == 6)
month = “Jumadil Tsani”;

else if (num == 7)
month = “Rajab”;

else if (num == 8)
month = “Syaban”;

else if (num == 9)
month = “Ramadhan”;

else if (num == 10)
month = “Syawal”;

else if (num == 11)
month = “Dzulqoidah”;

else if (num==12)
month = “Dzulhijjah”;

else
month = “out of range”;

return (month);
}

1 Response to "Hijriyah callendar using function"

mending pake “case” (atau “switch” ya? lupa kalo C++ pake yang mana) dari pada pake “if”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.