Sunday, March 19, 2017

Aturcara Soalan 8 20152016

Aturcara ini mengandungi ralat. Cari dan perbetulkan

#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
 char code;
 int countK,countI,countP,total;

 cout<<"\n Enter destination code: ";
 cin>>code;

    while(code!='Z')
    {
        if(code=='K')
        {countK=countK+1;
         total=total+8;}
        else if(code=='I')
        {
         countI=countI+1;
         total=total+18;
        }
        else if(code=='P')
        {
         countP=countP+1;
         total=total+24;
        }
        else
        cout<<"\n Invalid input";

     cout<<"\n Enter destination code: ";
     cin>>code;
    }

 cout<<"\n Passenger to KL:"<<countK;
 cout<<"\n Passenger to Ipoh:"<<countI;
 cout<<"\n Passenger to Pulau Pinang:"<<countP;
 cout<<"\n Total ticket price: RM"<<total;

return 0;
}