Last active
May 14, 2025 08:46
-
-
Save gaexe/082ef23cb89d155578f6 to your computer and use it in GitHub Desktop.
CONTOH PROGRAM C++ MENCARI NILAI RATA-RATA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<conio.h> | |
void main() { | |
float angka, total = 0, rata; | |
int jumlah; | |
cout << "1. Mencari Rata-rata. (jumlah angka ditentukan)" << endl; | |
cout << endl; | |
cout << "masukkan jumlah angka : "; cin >> jumlah; | |
cout << endl; | |
for (int i = 1; i <= jumlah; i++) { | |
cout << "Masukkan angka : "; cin >> angka; | |
total = total + angka; | |
} | |
cout << endl; | |
cout << "Total : " << total << endl; | |
rata = total / jumlah; | |
cout << "Rata-rata : " << rata; | |
getch(); | |
} |
I like how it clearly asks for the number of values first. But I'm a bit confused by the #include<iostream.h>
- that's an old-school way. In modern C++, we'd use #include <iostream>
. Also, the comment about the cin
issue is interesting.
Also, the comment about the
cin
issue is interesting.
I don't even remember what I did that year LMAO
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wah terima kasih banyak, daritadi saya nyari kenapa nilainya ga sesuai terus, eh ternyata cin ny malah pake variabel yg ada di kondisi for