Postingan lainnya
Program ini looping terus. Kenapa?
#include <iostream>
#include <string>
using namespace std;
int getOption(){
int input;
system("cls");
std::cout << "Program CRUD data Mahasiswa" << std::endl;
std::cout << "===========================" << std::endl;
std::cout << "1. Tambah data Mahasiswa" << std::endl;
std::cout << "2. Tampilkan data Mahasiswa" << std::endl;
std::cout << "3. Ubah data Mahasiswa" << std::endl;
std::cout << "4. Hapus data Mahasiswa" << std::endl;
std::cout << "5. Selesai" << std::endl;
std::cout << "===========================" << std::endl;
std::cout << "pilihan [1-5]? : ";
std::cin >> input;
return input;
}
int main(){
int pilihan = getOption();
char is_continue;
enum option{CREATE = 1, READ, UPDATE, DELETE, FINISH};
while(pilihan != FINISH){
switch (pilihan){
case CREATE:
std::cout << "Menambahkan data Mahasiswa" << std::endl;
break;
case READ:
std::cout << "Tampilkan data Mahasiswa" << std::endl;
break;
case UPDATE:
std::cout << "Ubah data Mahasiswa" << std::endl;
break;
case DELETE:
std::cout << "Hapus data Mahasiswa" << std::endl;
break;
default:
std::cout << "Pilihan tidak ditemukan" << std::endl;
break;
}
label_pilih:
std::cout << "Lanjut?(y/n) : ";
std::cin >> is_continue;
if ((is_continue == 'y') | (is_continue == 'Y')){
pilihan = getOption();
}else if ((is_continue == 'n') | (is_continue == 'N')){
break;
}else{
goto label_pilih;
break;
}
}
std::cout << "akhir dari Program" << std::endl;
return 0;
}
0
1 Jawaban:
<pre>}else if ((is_continue == 'n') | (is_continue == 'N')){ // tambahin ini FINISH = 5; break; }</pre><div><br></div>
0