C++ homework Problem

Reply

Join Date: Feb 2006
Posts: 7
Reputation: robase is an unknown quantity at this point 
Solved Threads: 0
robase robase is offline Offline
Newbie Poster

C++ homework Problem

 
0
  #1
Feb 26th, 2006
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;

}
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 482
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 47
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: C++ homework Problem

 
0
  #2
Feb 27th, 2006
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 %
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 482
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 47
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: C++ homework Problem

 
0
  #3
Feb 27th, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC