Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <string.h> //library-functions
- #include <ctype.h>
- #include <stdio.h>
- #include <locale.h>
- using namespace std;
- int selTimes(); //prototype
- void dispTicket();
- float calcAdult(int);
- float calcKids(int);
- void dispHighestPrice(float,float);
- void dispLowestAttendance(int,int);
- main()
- {
- int choice,run,i=0,amount1=0,amount2=0,max1=-9999,max2=-9999,total_ticket;
- float total_average,ticket_price1=0,ticket_price2=0,stop,sum1=0,sum2=0,sum3=0,sum4=0, total_price; //declare and initialize
- char ticket [10];
- run=selTimes();
- if(run <=0 || run>=3)
- cout<<"Sorry!but your choice is invalid!!!";
- else
- {
- while(i < run)
- {
- cout<<"\nSelect the matches(1/2):";
- cin >> choice;
- if(choice==1)
- {
- dispTicket(); //call functions
- do
- {
- cout << "\n\nEnter the ticket categories(ADULT/KIDS):";
- cin >> ws;
- cin.getline(ticket,10);
- for(int x=0;ticket[x]!='\0';x++)
- ticket[x]=toupper(ticket[x]);
- cout <<"Enter the amount of the ticket:";
- cin >> amount1;
- if(strcmp(ticket,"ADULT")==0)
- {
- ticket_price1=calcAdult(amount1);
- }
- else
- if(strcmp(ticket,"KIDS")==0)
- {
- ticket_price1=calcKids(amount1);
- }
- else
- cout <<"Sorry!but your choice is invalid!!!";
- if(ticket_price1 > max1)
- max1=ticket_price1;
- sum1=sum1+ticket_price1;
- sum2=sum2+amount1;
- cout<<"Press 0 to stop or another button to continue:";
- cin >> stop;
- }
- while(stop!=0);
- }
- else
- if(choice==2)
- {
- dispTicket();
- do
- {
- cout << "\n\nEnter the ticket categories(ADULT/KIDS):";
- cin >> ws;
- cin.getline(ticket,10);
- for(int x=0;ticket[x]!='\0';x++)
- ticket[x]=toupper(ticket[x]);
- cout <<"Enter the amount of the ticket:";
- cin >> amount2;
- if(strcmp(ticket,"ADULT")==0)
- {
- ticket_price2=calcAdult(amount2);
- }
- else
- if(strcmp(ticket,"KIDS")==0)
- {
- ticket_price2=calcKids(amount2);
- }
- else
- cout <<"Sorry!but your choice is invalid!!!";
- if(ticket_price2 > max2)
- max2=ticket_price2;
- sum3=sum3+ticket_price2;
- sum4=sum4+amount2;
- cout<<"Press 0 to stop or another button to continue:";
- cin >> stop;
- }
- while(stop!=0);
- }
- total_average= (sum1/sum2) + (sum3/sum4);
- total_ticket=sum2+sum4;
- total_price=sum1+sum3;
- ;
- i++;
- }
- setlocale(LC_ALL,"");
- cout<<"\nThe total ticket is:"<<total_ticket;
- printf("\nThe total price is: %.2f' JPY\n",total_price);
- printf("The average ticket price for one person is: %.2f' JPY\n",total_average);
- dispHighestPrice(max1,max2);
- dispLowestAttendance(sum2,sum4);
- }
- }
- int selTimes() //definition
- {
- int times;
- cout<<"\nWELCOME TO NISSAN STADIUM SYSTEM'S TICKET";
- cout<<"\nBELOW IS OUR NEXT TWO HOME MATCHES"<<endl;
- cout<<"-----------------------------------------------------------------------";
- cout<<"\n(1)YOKOHAMA F-MARINOS VS URAWA RED DIAMONDS [J1 LEAGUE,13TH DECEMBER 2017,2000 HRS(JAPANESE TIME)]";
- cout<<"\n(2)YOKOHAMA F-MARINOS VS KAWASAKI FRONTALE [J LEAGUE CUP,24TH DECEMBER 2017,1400 HRS(JAPANESE TIME)]";
- cout<<"\n\nHow many games you want to buy a ticket(1/2):";
- cin >> times;
- return times;
- }
- void dispTicket()
- {
- cout<<"\nTHE TICKET'S PRICE FOR THE ADULT IS 5300 JPY.";
- cout<<"\nTHE TICKET'S PRICE FOR THE KIDS IS 2100 JPY."<<endl;
- cout<<"-----------------------------------------------------------------------";
- cout << "\n***PLEASE NOTED THAT THE KIDS TICKET IS ONLY APPLIED TO THE KIDS UNDER 15 YEARS OLD***";
- }
- float calcAdult(int amnt)
- {
- return amnt*5300;
- }
- float calcKids(int amnt)
- {
- return amnt*2100;
- }
- void dispHighestPrice(float m1,float m2)
- {
- if(m1>m2)
- printf("The highest ticket price that has been purchased was %.2f JPY\n",m1); // %.2f printf up to 2 decimal places
- else
- printf("The highest ticket price that has been purchased was %.2f JPY\n",m2);
- }
- void dispLowestAttendance(int s2,int s4)
- {
- if(s2 < s4)
- cout << "The lowest match attendance was the match between'YOKOHAMA F-MARINOS VS URAWA RED DIAMONDS'with "<< s2 << " attendances.";
- else
- cout << "The lowest match attendance was the match between'YOKOHAMA F-MARINOS VS KAWASAKI FRONTALE'with "<< s4 << " attendances.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement