JonathanA007

Jonathan Arya Priguna/Tugas 8

Nov 22nd, 2023 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int panjang_string(string kata) {
  6.     return kata.length();
  7. }
  8.  
  9. string get_input(string prompt) {
  10.     string input;
  11.     cout << prompt;
  12.     getline(cin, input);
  13.     return input;
  14. }
  15.  
  16. int main() {
  17.     string nama, nim, mata_kuliah;
  18.     nama = get_input("Masukkan nama: ");
  19.     nim = get_input("Masukkan NIM: ");
  20.     mata_kuliah = get_input("Masukkan mata kuliah: ");
  21.  
  22.     if (nama.length() > 21) {
  23.         cout << "Error"<<endl;
  24.     } else {
  25.         cout << "Banyak karakter nama: " << panjang_string(nama) << endl;
  26.     }
  27.     if (nim.length() > 15) {
  28.         cout << "Error"<<endl;
  29.     } else {
  30.         cout << "Banyak karakter NIM: " << panjang_string(nim) << endl;
  31.     }
  32.     if (mata_kuliah.length() > 50) {
  33.         cout << "Error"<<endl;
  34.     } else {
  35.         cout << "Banyak karakter mata kuliah: " << panjang_string(mata_kuliah) << endl;
  36.     }
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment