Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int panjang_string(string kata) {
- return kata.length();
- }
- string get_input(string prompt) {
- string input;
- cout << prompt;
- getline(cin, input);
- return input;
- }
- int main() {
- string nama, nim, mata_kuliah;
- nama = get_input("Masukkan nama: ");
- nim = get_input("Masukkan NIM: ");
- mata_kuliah = get_input("Masukkan mata kuliah: ");
- if (nama.length() > 21) {
- cout << "Error"<<endl;
- } else {
- cout << "Banyak karakter nama: " << panjang_string(nama) << endl;
- }
- if (nim.length() > 15) {
- cout << "Error"<<endl;
- } else {
- cout << "Banyak karakter NIM: " << panjang_string(nim) << endl;
- }
- if (mata_kuliah.length() > 50) {
- cout << "Error"<<endl;
- } else {
- cout << "Banyak karakter mata kuliah: " << panjang_string(mata_kuliah) << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment