Last active
November 27, 2016 11:15
-
-
Save rmsubekti/429f3f930112e23468630e6d37d45495 to your computer and use it in GitHub Desktop.
Mencari nama pada daftar nama
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> | |
#include <string> | |
#include <conio.h> | |
using namespace std; | |
//11.12.5800 | |
int main() { | |
//Deklarasi variabel | |
string nama[5], cari; | |
int jumlah = sizeof(nama) / sizeof(nama[5]), ketemu = 0; | |
//User menginputkan 5 nama ke array nama | |
cout << "Masukkan Nama Mahasiswa : " << endl; | |
for (int i = 0; i < jumlah; i++) | |
{ //Input nama termasuk nama dengan spasi | |
cout << i + 1 << ". ";getline(cin, nama[i]); | |
} | |
//Pencarian menggunakan Sequential search | |
cout << "\nMasukkan nama yang dicari : "; getline(cin, cari); | |
for (int i = 0; i < jumlah; i++) | |
if (nama[i].compare(cari) == 0) | |
{ //cek apakah nama yang dicari ada di elemen nama[n] | |
ketemu = 1; | |
cout << "\nNama ditemukan pada posisi ke-" << i + 1 << endl; | |
} | |
//juka nilai variabel ketemu tidak berubah | |
//berarti nama yang dicari tidak ditemukan | |
if ( ketemu == 0 ) | |
cout << "\nTidak ada yang cocok dengan nama yang anda cari." << endl; | |
_getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment