Panah Shape dengan Perulangan

#include <iostream>
#include <conio.h>
#include <iomanip>
#include <string.h>
using namespace std;

int main()
{
    awal:
    int x,b,c,d,e,h,i,j,z, base, chomp,chimp,alas,max,panjang;
    int kiri, tengah, kanan;
    char pilihan,pil,pil2,pil3;
    string initial, zul;
   
    cout<<"=========================="<<endl;
    c=1;//setingan batang pertama 1
    cout<<"Masukan Besar Panah: ";
    cin>>base;//menginput besarnya panah
   
    //==========================================================================
    inisialisasi://menidentifikasi inputan ganjil atau genap
    if( base%2 == 0)
    {
            zul = "genap";
            initial="genap";
    }
    if( base%2 != 0)
    {       
             zul = "ganjil";
             initial="ganjil";
    }
    cout<<"base: "<<initial;        
    cout<<endl;//akhir inisialisai inputan
    //==========================================================================
   
    atas ://mengidentifikasi jumlah alas piramid
    alas=(base*2)-1;
    cout<<"Jumlah Alas Piramid: ";
    cout<<alas;
    cout<<endl;//end
    cout<<"=========================="<<endl;
   
    bawah:
    if(zul == "genap")//mengidentifikasi jumlah batang panah
    {
           kiri= base/2;
           tengah=base-1;
           kanan= alas-(kiri+tengah);
    }
    else if (zul == "ganjil")
    {
            kiri= base/2;
            tengah= base;
            kanan= alas-(kiri+tengah);
    }
   
    cout<<"\n"<<setw((kiri/2)+1)<<kiri<<setw(tengah-(kiri/2))<<tengah<<setw((kanan+(kiri/2))+1)<<kanan;
    cout<<endl<<"\n";//end
   
    //==========================================================
    //==========================================================
    for(x=1; x<=base; x++)//codingan piramid
    {
             d = base-x;
             for(b=1; b<=d; b++)
             {
                      cout<<" ";
             }
             for(e=1; e<=c; e++)
             {
                      cout<<"*";
             }
             c=c+2;
             cout<<endl;
    };//end coding piramid
   
    if(zul == "genap" )//batang genap
    {
             panjang = base + 1 ;
             for(h=1; h<=panjang; h++)//codingan batang
             {
                      chomp=base/2;
                      for(i=1; i<=chomp; i++)
                      {
                               cout<<" ";
                      }
                      chimp=base-1;
                      for(j=1; j<=chimp; j++)
                      {
                               cout<<"*";
                               }
             cout<<endl;
             }//end coding batang
    }//end if
    else if(zul == "ganjil" )//batang ganjil
    {
              panjang = base + 1;     
              for(h=1; h<=panjang; h++)//codingan batang
              {
                       chomp=base/2;
                       for(i=1; i<=chomp; i++)
                       {
                                cout<<" ";
                       }
                       chimp=base;
                       for(j=1; j<=chimp; j++)
                       {
                                cout<<"*";
                       }
              cout<<endl;
              }//end coding batang
    }
cout<<endl;
cout<<endl;

//menu pilihan ulang dan exit
menu1:
cout<<"EXIT (Y/N) :";
cin>>pilihan;
if( pilihan == 'Y' || pilihan == 'y' )//Exit
{
  cout<<"\n-Are You Sure To EXIT (Y/N) : ";
  cin>>pil;
  if ( pil == 'Y' || pil == 'y' )//confirm Exit
  {
       return 0;
  }
 
  else if ( pil == 'N' || pil == 'n' )//meminta ulang
  {
      cout<<"-Do You Want Back To Top (Y/N) : ";
      cin>>pil2;
      cout<<endl;
      if ( pil2 == 'Y' || pil2 == 'y' )
      {
           cout<<"**Selamat Mencoba**";
           getch();
           system("cls");  
           goto awal;
      } 
      else if ( pil2 == 'N' || pil2 == 'n' )//kembali tanya exit
      {
            getch();
            goto menu1;
      }
  }
  
  else
  getch();
  goto menu1;
 
}

else if( pilihan == 'N' || pilihan == 'n' )//kembali ke awal
{
  cout<<"Selamat Mencoba";
  getch();
  system("cls");  
  goto awal;
}
else
{
    cout<<"System EROR";
}   
getch();
return 0;
}

Komentar

Postingan Populer