944,198 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2241
  • C++ RSS
Feb 26th, 2006
0

C++ homework Problem

Expand Post »
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;

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
robase is offline Offline
7 posts
since Feb 2006
Feb 27th, 2006
0

Re: C++ homework Problem

Quote originally posted by robase ...
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 %
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Feb 27th, 2006
0

Re: C++ homework Problem

Quote originally posted by robase ...
#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
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: home work help please
Next Thread in C++ Forum Timeline: needing help figuring out





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC