I have an Amusement Park Problem in C++

Category
Children
Price $2.00
The first child is always free
Category
Youth
Price
$8.50
For every 4 tickets in this group one person is free.
Buy 4,get one free
Category
Adult
Price $12.50
After 10 adult tickets,the price is $9.00 per ticket.
The first 10 tickets are always $12.50

I tried doing a double while statement but it didn't work.Could I have an hint for the buy 4 get 1 free and After 10 adult tickets,the price is $9.00 per ticket
Here is my code

// Author:            Robert
// Source file:       Project2.cpp
//Description:        Fanzone Amusement Park
//Compiler:           Microsoft Visual Studio.NET



#include "stdafx.h"
#include <iostream>
using namespace std;


int main()


{
int number_of_Children_tickets = 0;
int number_of_free_Children_tickets = 0;
int number_of_Youth_tickets = 0;
int number_of_free_Youth_tickets = 0;


int number_of_Adult_tickets = 0;
int number_of_tickets = 0;


int total_number_of_Children_tickets = 0;
int total_number_of_Youth_tickets = 0;
int total_number_of_Adult_tickets = 0;


//double price_of_free_Youth_tickets = 0.00;
//double price_of_free_Children_tickets = 0.00;
double price_of_Children_tickets = 2.00;
double price_of_Youth_tickets = 8.50;
double price_of_Adult_tickets = 12.50;
double Total_of_Children_tickets = 0.0;
double Total_of_Youth_tickets = 0.0;
double Total_of_Adult_tickets = 0.0;
//double Total_of_free_Children_tickets;
//double Total_of_free_Youth_tickets;


double Total = 0.0;


int Total_Tickets = 0;
while (number_of_Children_tickets != -1)



{
cout << "Enter the number of Children tickets you would like to purchase and press enter.\n";
cin >> number_of_Children_tickets;
if (number_of_Children_tickets != -1)


{
total_number_of_Children_tickets += number_of_Children_tickets;
cout << "Enter the number of Youth tickets you would like to purchase and press enter.\n";
cin >> number_of_Youth_tickets;
total_number_of_Youth_tickets += number_of_Youth_tickets;
cout << "Enter the number of Adult tickets you would like to purchase and press enter.\n";
cin >> number_of_Adult_tickets;
total_number_of_Adult_tickets += number_of_Adult_tickets;
}
//cout << "Enter the number of free Childrens tickets you would like and press enter.\n";
//cin >> number_of_free_Children_tickets;


}


if (total_number_of_Children_tickets > 0)


{
number_of_free_Children_tickets = 1;



}
Total_of_Children_tickets = (price_of_Children_tickets * (total_number_of_Children_tickets - number_of_free_Children_tickets));
Total_of_Youth_tickets = (price_of_Youth_tickets * total_number_of_Youth_tickets - number_of_free_Children_tickets);
Total_of_Adult_tickets = (price_of_Adult_tickets * total_number_of_Adult_tickets);



Total = Total_of_Children_tickets - number_of_free_Children_tickets + Total_of_Youth_tickets + Total_of_Adult_tickets;
Total_Tickets = total_number_of_Children_tickets + total_number_of_Youth_tickets + total_number_of_Adult_tickets;


if ((Total_Tickets >= 20) || (total_number_of_Youth_tickets >= 8))
{
Total += 25.00;
}


cout << "Type of Ticket   Tickets    Price    Total\n";
cout << "Children          " << total_number_of_Children_tickets - number_of_free_Children_tickets << "         " << price_of_Children_tickets << "      " << Total_of_Children_tickets << "\n";
cout << "Youth             " << total_number_of_Youth_tickets << "            " << price_of_Youth_tickets << "      " << Total_of_Youth_tickets << "\n";
cout << "Adult             " << total_number_of_Adult_tickets << "            " << price_of_Adult_tickets << "      " << Total_of_Adult_tickets << "\n";
cout << "Free Children Tickets             " << number_of_free_Children_tickets << "            " << number_of_free_Children_tickets << "\n";


//cout << number_of_tickets << "Children_tickets\n";
//cout << number_of_tickets << " Youth_tickets\n";
//cout << number_of_tickets << " Adults_tickets\n";
cout << Total << " - Total\n";
cin >> number_of_Youth_tickets;


return 0;


}

Recommended Answers

All 2 Replies

Could I have an hint for the buy 4 get 1 free and After 10 adult tickets

Think back to primary school mathematics - Think about the calculation you would do, to work out how many free tickets you would get when you buy 10.

Hint - C++ has the "divide by" operator / ... which on integers returns only the whole number. Any remaining 'fractions' are lost.
For the remainder, use the "modulus" operator %

#include "stdafx.h"

On a different subject, you may be pleased to know that you can disable precompiled headers in MSVC++ 2003 (And probably 2005 too, although i've never used 2005) - right click on your project in the solution explorer window, and choose "properties"

in the left-hand pane of the properties window, expand on the item/folder called C/C++

From the list of C/C++ options, choose "Precompiled headers"

Go to the right-hand pane now, and change the option to "Not Using Precompiled Headers"

the 2 boxes beneath can be cleared and left blank

press "OK".

Now you will not get the error when you compile your project without stdafx.h

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.