30 November 2011

Effand Nozh

C++ Membuat Program Rata-rata Umur

Obatbodoh Blogs - Belajar lagi C++ biar tambah suiipp,, yach dari pada kebanyakan tidur mending nyobak-nyobak C++ nya terus kalau jadi ya sukur bisa di posting kalau pun gag jadi ya west gag jadi diposting.

Untungnya kali ini jadi dan ini juga cari referensi di internet, haa.. Tapi ya gak pa2 lah yang penting suatu saat dapat berguna.

Langsung coba dech script ini untuk mengetahui Rata-rata umur siswa ataupun rata-rata umur siapapun.
//program untuk menghitung rata-rata umur
#include <iostream.h>
main ()
{
// declaration of variables, the age will be in whole numbers
int age1, age2, age3, age4, afe5;
int TotalAge, AverageAge;
// take ages of the students from the user
cout << "Please enter the age of student 1: ";
cin >> age1; 
cout << "Please enter the age of student 2: ";
cin >> age2;
cout << "Please enter the age of student 3: ";
cin >> age3;
cout << "Please enter the age of student 4: ";
cin >> age4;
cout << "Please enter the age of student 5: ";
cin >> age5;
// calculate the total age and average age
TotalAge = age1 + age2 + age3 + age4 + age5;
AverageAge = TotalAge / 5;
// Display the result ( average age )
cout << "Average age of class is: " << AverageAge;
}


Hasilnya kurang lebih seperti ini :
Please enter the age of student 1: 12  Please enter the age of student 2: 13 Please enter the age of student 3: 11 Please enter the age of student 4: 14 Please enter the age of student 5: 13 Average age of class is: 12
Jika article ini bernmanfaat bagi anda, silahkan teinggalkan comentar anda untuk menghargai karya orang lain. Semoga bermanfaat.

Effand Nozh

About Effand Nozh -

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :