Advertisement
vergepuppeter

Kau punya C++

Dec 18th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.03 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <string.h> //library-functions
  11. #include <ctype.h>
  12. #include <stdio.h>
  13. #include <locale.h>
  14. using namespace std;
  15. int selTimes(); //prototype
  16. void dispTicket();
  17. float calcAdult(int);
  18. float calcKids(int);
  19. void dispHighestPrice(float,float);
  20. void dispLowestAttendance(int,int);
  21.  
  22. main()
  23. {
  24.     int choice,run,i=0,amount1=0,amount2=0,max1=-9999,max2=-9999,total_ticket;
  25.     float total_average,ticket_price1=0,ticket_price2=0,stop,sum1=0,sum2=0,sum3=0,sum4=0, total_price; //declare and initialize
  26.     char ticket [10];
  27.     run=selTimes();
  28.  
  29.     if(run <=0 || run>=3)
  30.         cout<<"Sorry!but your choice is invalid!!!";
  31.     else
  32.     {
  33.         while(i < run)
  34.         {
  35.             cout<<"\nSelect the matches(1/2):";
  36.             cin >> choice;
  37.             if(choice==1)
  38.             {
  39.                 dispTicket(); //call functions
  40.                 do
  41.                 {
  42.                     cout << "\n\nEnter the ticket categories(ADULT/KIDS):";
  43.                     cin >> ws;
  44.                     cin.getline(ticket,10);
  45.                     for(int x=0;ticket[x]!='\0';x++)
  46.                         ticket[x]=toupper(ticket[x]);
  47.                     cout <<"Enter the amount of the ticket:";
  48.                     cin >> amount1;
  49.                        
  50.                     if(strcmp(ticket,"ADULT")==0)
  51.                     {
  52.                         ticket_price1=calcAdult(amount1);
  53.                     }
  54.                     else
  55.                         if(strcmp(ticket,"KIDS")==0)
  56.                         {
  57.                             ticket_price1=calcKids(amount1);
  58.                         }
  59.                     else
  60.                         cout <<"Sorry!but your choice is invalid!!!";
  61.                     if(ticket_price1 > max1)
  62.                         max1=ticket_price1;
  63.                     sum1=sum1+ticket_price1;  
  64.                     sum2=sum2+amount1;    
  65.                     cout<<"Press 0 to stop or another button to continue:";
  66.                     cin >> stop;      
  67.                 }
  68.                 while(stop!=0);
  69.             }
  70.        
  71.             else
  72.                 if(choice==2)
  73.                 {
  74.                     dispTicket();
  75.                     do
  76.                     {
  77.                         cout << "\n\nEnter the ticket categories(ADULT/KIDS):";
  78.                         cin >> ws;
  79.                         cin.getline(ticket,10);
  80.                         for(int x=0;ticket[x]!='\0';x++)
  81.                             ticket[x]=toupper(ticket[x]);
  82.                         cout <<"Enter the amount of the ticket:";
  83.                         cin >> amount2;
  84.                            
  85.                         if(strcmp(ticket,"ADULT")==0)
  86.                         {
  87.                             ticket_price2=calcAdult(amount2);
  88.                         }
  89.                         else
  90.                             if(strcmp(ticket,"KIDS")==0)
  91.                             {
  92.                                 ticket_price2=calcKids(amount2);
  93.                             }
  94.                         else
  95.                             cout <<"Sorry!but your choice is invalid!!!";
  96.                         if(ticket_price2 > max2)
  97.                             max2=ticket_price2;
  98.                         sum3=sum3+ticket_price2;  
  99.                         sum4=sum4+amount2;
  100.                         cout<<"Press 0 to stop or another button to continue:";
  101.                         cin >> stop;      
  102.                     }
  103.                     while(stop!=0);
  104.                 }
  105.             total_average= (sum1/sum2) + (sum3/sum4);
  106.             total_ticket=sum2+sum4;
  107.             total_price=sum1+sum3;
  108.             ;
  109.             i++;
  110.         }
  111.     setlocale(LC_ALL,"");
  112.     cout<<"\nThe total ticket is:"<<total_ticket;
  113.     printf("\nThe total price is: %.2f' JPY\n",total_price);
  114.     printf("The average ticket price for one person is: %.2f' JPY\n",total_average);
  115.     dispHighestPrice(max1,max2);
  116.     dispLowestAttendance(sum2,sum4);  
  117.     }  
  118. }
  119.  
  120.  
  121. int selTimes() //definition
  122. {
  123.     int times;
  124.     cout<<"\nWELCOME TO NISSAN STADIUM SYSTEM'S TICKET";
  125.     cout<<"\nBELOW IS OUR NEXT TWO HOME MATCHES"<<endl;
  126.     cout<<"-----------------------------------------------------------------------";
  127.     cout<<"\n(1)YOKOHAMA F-MARINOS VS URAWA RED DIAMONDS [J1 LEAGUE,13TH DECEMBER 2017,2000 HRS(JAPANESE TIME)]";
  128.     cout<<"\n(2)YOKOHAMA F-MARINOS VS KAWASAKI FRONTALE [J LEAGUE CUP,24TH DECEMBER 2017,1400 HRS(JAPANESE TIME)]";
  129.     cout<<"\n\nHow many games you want to buy a ticket(1/2):";
  130.     cin >> times;
  131.    
  132.     return times;
  133. }
  134.  
  135. void dispTicket()
  136. {
  137.     cout<<"\nTHE TICKET'S PRICE FOR THE ADULT IS 5300 JPY.";
  138.     cout<<"\nTHE TICKET'S PRICE FOR THE KIDS IS 2100 JPY."<<endl;
  139.     cout<<"-----------------------------------------------------------------------";
  140.     cout << "\n***PLEASE NOTED THAT THE KIDS TICKET IS ONLY APPLIED TO THE KIDS UNDER 15 YEARS OLD***";
  141. }
  142.  
  143. float calcAdult(int amnt)
  144. {
  145.     return amnt*5300;
  146. }
  147.  
  148. float calcKids(int amnt)
  149. {
  150.     return amnt*2100;
  151. }
  152.  
  153. void dispHighestPrice(float m1,float m2)
  154. {
  155.     if(m1>m2)
  156.         printf("The highest ticket price that has been purchased was %.2f JPY\n",m1); // %.2f printf up to 2 decimal places
  157.     else
  158.         printf("The highest ticket price that has been purchased was %.2f JPY\n",m2);
  159. }
  160.  
  161. void dispLowestAttendance(int s2,int s4)
  162. {
  163.     if(s2 < s4)
  164.         cout << "The lowest match attendance was the match between'YOKOHAMA F-MARINOS VS URAWA RED DIAMONDS'with "<< s2 << " attendances.";
  165.     else
  166.         cout << "The lowest match attendance was the match between'YOKOHAMA F-MARINOS VS KAWASAKI FRONTALE'with "<< s4 << " attendances.";
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement