MATERI-MATERI MATA KULIAH SISTEM INFORMASI STMIK MDP

Pasang Iklan Gratis Disini !!!

ads ads ads ads

Sabtu, 06 November 2010

Contoh Pernyataan While

. Sabtu, 06 November 2010

#include <iostream>
using namespace std;
void main()
{
 long int pass;
cout<<"=================================\n";
cout<<"NPM : ";cin>>pass;
cout<<"=================================\n";
 while(pass!=2010240001)
 {
  cout<<"SALAH INPUT NPM ! INPUT LAGI\n";
  cout<<"    NPM  :  ";cin>>pass;
 cout<<"=================================\n";
 }
 cout<<" SELAMAT DATANG DI SI1C \n";
 system ("pause");
}

Contoh 2:

#include <iostream>
using namespace std;
void main()
{
 long int pass;
cout<<"=================================\n";
cout<<"1. NASI GORENG SPESIAL\n";
cout<<"2. ROTI BAKAR ISTIMEWA\n";
cout<<"=================================\n";
cout<<"PILIH MENU (1/2) ";cin>>pass;
cout<<"=================================\n";
 while((pass<1) || (pass>2))
 {
  cout<<"SALAH PILIH MENU ! PILIH LAGI\n";
 cout<<"PILIH MENU (1/2) ";cin>>pass;
 cout<<"=================================\n";
 }
 cout<<" TERIMA KASIH \n";
 system ("pause");
}


Contoh 2:
#include <iostream>
using namespace std;
void main()
{
 long int pass, nilai;
cout<<"=================================\n";
cout<<"1. NASI GORENG SPESIAL\n";
cout<<"2. ROTI BAKAR ISTIMEWA\n";
cout<<"=================================\n";
cout<<"PILIH MENU (1/2) ";cin>>pass;
cout<<"=================================\n";
 while((pass!=1) && (pass!=2))
 {
  cout<<"SALAH PILIH MENU ! PILIH LAGI\n";
 cout<<"PILIH MENU (1/2) ";cin>>pass;
 cout<<"=================================\n";
 }

 cout<<" TERIMA KASIH \n";
 system ("pause");
}


Contoh 3:
#include <iostream>
using namespace std;
void main()
{

 long int pass, nilai;
 int total_harga ;

cout<<"=================================\n";
cout<<"1. NASI GORENG SPESIAL\n";
cout<<"2. ROTI BAKAR ISTIMEWA\n";
cout<<"=================================\n";
cout<<"PILIH MENU (1/2) ";cin>>pass;
cout<<"=================================\n";

 while((pass!=1) && (pass!=2)){
    cout<<"SALAH PILIH MENU ! PILIH LAGI\n";
    cout<<"PILIH MENU (1/2) ";cin>>pass;
    }
    cout<<"=================================\n";
 if (pass==1){
    cout<<"Harga per porsi : Rp. 25.000\n";
    cout<<"Jumlah pemesanan : ";cin>>nilai;
    total_harga=nilai*25000;
    cout<<"Total Harga Nasi : Rp. "<<total_harga<<endl;
    }
 else if (pass==2){
    cout<<"Harga per porsi : Rp. 15000\n";
    cout<<"Jumlah Pemesanan : ";cin>>nilai;
    total_harga=nilai*15000;
    cout<<"Total Harga Roti = Rp."<<total_harga<<endl;
    }

 cout<<" TERIMA KASIH \n";
 system ("pause");
}

Contoh 4 //belum pasti:
#include <iostream>
using namespace std;
void main()
{

 int pass=0, nilai;
 long int total_harga ;
 while (pass!=3){
     system ("cls");

cout<<"=================================\n";
cout<<"1. NASI GORENG SPESIAL\n";
cout<<"2. ROTI BAKAR ISTIMEWA\n";
cout<<"3. EXIT\n";
cout<<"=================================\n";
cout<<"PILIH MENU (1/2/3) ";cin>>pass;
cout<<"=================================\n";

 while((pass!=1) && (pass!=2) && (pass!=3) ){
    cout<<"SALAH PILIH MENU ! PILIH LAGI\n";
    cout<<"PILIH MENU (1/2/3) ";cin>>pass;
    }
    cout<<"=================================\n";
 if (pass==1){
    cout<<"Harga per porsi : Rp. 25.000\n";
    cout<<"Jumlah pemesanan : ";cin>>nilai;
    total_harga=nilai*25000;
    cout<<"Total Harga Nasi : Rp. "<<total_harga<<endl;
    }
 else if (pass==2){
    cout<<"Harga per porsi : Rp. 15000\n";
    cout<<"Jumlah Pemesanan : ";cin>>nilai;
    total_harga=nilai*15000;
    cout<<"Total Harga Roti = Rp."<<total_harga<<endl;
    }

 cout<<" TERIMA KASIH \n";
 system ("pause");
}
}

SEMOGA BERMANFAAT

0 komentar:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Posting Komentar

Tuliskan Komentar Disini..

Related Posts Plugin for WordPress, Blogger...
 
{Sistem Informasi} is proudly powered by Blogger.com | Template by : Sukriyadi | sukriyadi.blogspot.com