Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
#include <conio.h>
#define MAX 6
typedef struct{
int data[MAX];
int head;
int tail;
} Queue;
Queue antrian;
void Create(){
antrian.head=antrian.tail=-1;
}

int IsEmpty(){
if(antrian.tail==-1)
return 1;
else
return 0;
}

int IsFull(){
if (antrian.tail==MAX-1) return 1;
else return 0;
}

void Enqueue(int data){
if(IsEmpty()==1){
antrian.head=antrian.tail=0;
antrian.data[antrian.tail]=data;

printf("\t Silahkan Masuk !! \n",antrian.data[antrian.tail]);
void Tampil();
{
if(IsEmpty()==0){
for(int i=antrian.head;i<=antrian.tail;i++){
printf("%d ",antrian.data[i]);
}
}else printf("data kosong!");
};
}else
if(IsFull()==0){
antrian.tail++;
antrian.data[antrian.tail]=data;
printf("\t Silahkan Masuk !! \n",antrian.data[antrian.tail]);
}

}

int Dequeue(){
int i;
int e = antrian.data[antrian.head];
for(i=antrian.head;i<=antrian.tail-1;i++){
antrian.data[i]= antrian.data[i+1];
}
antrian.tail--;
return e;
}


void clear(){
antrian.head=antrian.tail=-1;
printf("Data Clear");
}
void Tampil()
{ int jum;
jum=0;

if(IsEmpty()==0){
for(int i=antrian.head;i<=antrian.tail;i++){
jum++;

printf("\n| %d |",antrian.data[i]);}
printf("\njumlah yang mengantri saat ini %i orang",jum);
}else printf("Data Kosong!\n");}

//sebagai nasabah
void nasabah()
{
int data;
char lagi;
do{
clrscr();
printf("\t+=================================+\n");
printf("\t| menu nasabah |\n");
printf("\t+=================================|\n");
printf("\t| tekan (a) untuk masukkan data |\n");
printf("\t| tekan (b) melihat data antrian |\n");
printf("\t| tekan (x) keluar |\n");
printf("\t+=================================|\n");
printf("pilihan : "); scanf("%c",&lagi);
if((lagi=='x') || (lagi=='X'))
{ printf("terima kasih\n");

break;
}

switch(lagi)
{
case 'a':
printf("masukkan data: "); scanf("%d",&data);
Enqueue(data);
break;
case 'b': Tampil();
break;

}getch();
} while(lagi !='x');
getche();
}

//memasukkan password
void password()
{
char nama[20], id[10], password[4];
int i;
{
clrscr();

atas:
clrscr();
printf("\t\t+===============================================+\n");
printf("\t\t| S E L A M A T D A T A N G |\n");
printf("\t\t| jika anda admin dari teller |\n");
printf("\t\t|Silahkan masukkan User Name & 3 digit Password |\n");
printf("\t\t+===============================================+\n");
printf("\t\t UserName : ") ; cin>>nama;
printf("\t\t No. Identitas : "); cin>>id;
printf("\t\t Password : ") ;
for(i=0; i<=2; i++)
{password[i]=getche(); printf("\bX");
}
printf("\n\t\t+=============================================+\n");
if (strcmp(password,"aaa")==0)
{ printf("\n\n\t\t Anda Masuk Sebagai TEllER\n");
printf("\t\t User : %s \n",nama);
printf("\t\t No. Identitas : %s\n",id);
printf("\n\n\t\tTekan Sembarang tombol untuk ke menu teller..!");
goto bawah;
}
else
{
printf("\t\t\tpassword salah bro...hahaaa\n");
printf("\t\tketik sembarang tombol untuk kembali ke menu: ");
goto atas;

}
bawah:
getch();
}
}

void teller()
{char menu;
password();
do{
clrscr();
printf("\t\t+=================================+\n");
printf("\t\t| menu pilihan untuk TELLER |\n");
printf("\t\t+=================================+\n");
printf("\t\t| tekan (a) untuk menghapus data |\n");
printf("\t\t| tekan (b) melihat data antrian |\n");
printf("\t\t| tekan (c) untuk mereset |\n");
printf("\t\t| tekan (x) untuk keluar |\n");
printf("\t\t+=================================+\n");
printf("pilihan : "); scanf("%c",&menu);
if((menu=='x') || (menu=='X'))
{ printf("terima kasih\n");

break;
}

switch(menu)
{
case 'a': printf("Elemen yang keluar : %d",Dequeue());
break;
case 'b': Tampil();
break;
case 'c': clear();
break;
}getch();
} while(menu !='x');

}

void main(){
char pil;


Create();
do{
clrscr();
fflush(stdin);
printf("\t\t+=====================================+\n");
printf("\t\t| Bank Republik Indonesia|\n");
printf("\t\t| jalan Teuku Umar |\n");
printf("\t\t| Bali |\n");
printf("\t\t+=====================================+\n");
printf("\t\t| tekan (n) untuk Nasabah |\n");
printf("\t\t| tekan (t) untuk Teller |\n");
printf("\t\t| tekan (k) keluar dari program |\n");
printf("\t\t+=====================================+\n");
printf("pilihan : "); scanf("%c",&pil);
if((pil=='k') || (pil=='k'))
{ printf("terima kasih");
break;
}

switch(pil)
{
case 'n': nasabah();
break;
case 't': teller();
break;

}

}while(pil!='k');
}


What I have tried:

can anyone help me ? Why this code is error ?
Posted
Updated 11-May-20 6:37am
Comments
[no name] 11-May-20 11:51am    
And the error is?
Compiling error or you don't get the result you expect?
aris mihadjami 11-May-20 11:56am    
when I execute an error occurs, "cin >> name;" this error
[no name] 11-May-20 12:04pm    
And what is the error message?
Does mabye the error occurs only in case you enter more than 20 characters? If yes try this cin.getline(name, sizeof(name));
aris mihadjami 11-May-20 12:11pm    
When I want to compile n run, an error occurs in the section "cin>>name;"
[no name] 11-May-20 12:19pm    
I give up, sorry...

1 solution

Start by indenting your code: "flat to the left hand side" doesn't help anyone understand your code, especially you.
Which of these is easier to read?
C++
int IsEmpty(){
if(antrian.tail==-1)
return 1;
else
return 0;
}
C++
int IsEmpty(){
   if(antrian.tail==-1)
      return 1;
   else
      return 0;
}
C++
int IsEmpty()
   {
   if(antrian.tail==-1)
      {
      return 1;
      }
   else
      {
      return 0;
      }
   }
Here is a clue: It's not the first one ...
Indentation helps everybody see what is going on more clearly: where functions begin and end, what is - and isn't - inside a struct, how the code flow works.
So pick an indentation style[^] and stick to it. (I like Whitesmiths, but it's not to everybody's taste) It'll make your coding a lot easier once you get used to the idea. And at least while you are beginning, always use curly braces for code in an if, else, or similar, even if it's one line: it's far too easy to miss something if you don't:
C++
if (a == b) 
   c = 2; d =3;
is not the same as
C++
if (a == b)
   { 
   c = 2; d =3;
   }
Or better
C++
if (a == b)
   { 
   c = 2; 
   d =3;
   }


And forget labels, forget goto - pretend they don't even exist for a couple of years - no code you are going to write will need one, there are loads of ways to loop that won't make people laugh at your code or (in extreme cases) beat you with a cluebat until blood comes out your ears.

When you've done all that, you'll probably have already fixed the problem you've noticed without even being aware of it ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900