| | |
C++ homework Problem
![]() |
•
•
Join Date: Feb 2006
Posts: 7
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
•
•
Originally Posted by robase
Could I have an hint for the buy 4 get 1 free and After 10 adult tickets
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 %
•
•
•
•
Originally Posted by robase
#include "stdafx.h"
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
![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- Abstract class homework problem (C++)
- % problem (Java)
- gcd problem (C++)
- A problem with a given Syntax! (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: home work help please
- Next Thread: needing help figuring out
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple net news node number numbertoword output parameter payment pointer problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets





