fork download
  1. #include <iostream>
  2. #include <cctype> // untuk fungsi isdigit, isupper, islower
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. string password;
  8. int digitCount = 0, upperCount = 0, lowerCount = 0, symbolCount = 0;
  9.  
  10. // Membaca input kata sandi dari pengguna
  11. cout << "Masukkan kata sandi: ";
  12. getline(cin, password);
  13.  
  14. // Menghitung jumlah karakter
  15. for (char c : password) {
  16. if (isdigit(c)) {
  17. digitCount++;
  18. } else if (isupper(c)) {
  19. upperCount++;
  20. } else if (islower(c)) {
  21. lowerCount++;
  22. } else {
  23. symbolCount++;
  24. }
  25. }
  26.  
  27. // Menampilkan hasil
  28. cout << "Jumlah angka: " << digitCount << endl;
  29. cout << "Jumlah huruf kapital: " << upperCount << endl;
  30. cout << "Jumlah huruf kecil: " << lowerCount << endl;
  31. cout << "Jumlah simbol: " << symbolCount << endl;
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5272KB
stdin
 
stdout
Masukkan kata sandi: Jumlah angka: 0
Jumlah huruf kapital: 0
Jumlah huruf kecil: 0
Jumlah simbol: 1