Skip to content

Instantly share code, notes, and snippets.

@gaexe
Last active May 14, 2025 08:46
Show Gist options
  • Save gaexe/082ef23cb89d155578f6 to your computer and use it in GitHub Desktop.
Save gaexe/082ef23cb89d155578f6 to your computer and use it in GitHub Desktop.
CONTOH PROGRAM C++ MENCARI NILAI RATA-RATA
#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();
}
@dayeeen
Copy link

dayeeen commented Nov 23, 2021

Wah terima kasih banyak, daritadi saya nyari kenapa nilainya ga sesuai terus, eh ternyata cin ny malah pake variabel yg ada di kondisi for

@freddavis980
Copy link

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.

@dayeeen
Copy link

dayeeen commented May 14, 2025

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