Amusement Park tickets Help

I'm not sure really where to start or how to do this code and it is due very soon. If anyone could help me that would be great even an example that can point me in the right direction would be great. Here is what the assignment:

Write a C++ program to get the input of number of tickets for an amusement park. Each ticket costs $ 5.50. Every fifth ticket is free. If any person is less than 5 or greater than 65 (by age), then they get a discount of 1.08. Calculate the total price for group of visitors.



#include <iostream>
using namespace std;

int main()
{
int visitors;
int age;
int i;
double total = 0;
double discountprice;

cout << "Please enter the number of visitors: " << endl;
cin >> visitors;

for (i = 1; i <= visitors; i++)
{
if (1 % 5 == 0)** // Every 5th ticket is free
cout << "Your ticket is free!" << endl;

else if (age)

cout << "Please enter age of visitor: " << endl;
cin >> age;

if (age < 5 || age > 65)++ //find discount is younger than 5 or older than 65

cout << "You get a discount of 1.08" << discountprice << endl; // calculate discount
discountprice = 5.50 - 1.08 + total


else if (age)

cout << "Please enter age of visitor: " << endl;
cin >> age;

cout << "Your total is: " << total << endl;
}
return 0;
}
In my class we have yet to learn Array's, though now it is having an error at the discountprice
Line 20: age is an uninitialized variable. You haven't asked for it yet. if (age) is unneeded here.

Line 27: You're trying to output discountprice before you calculate it.

Line 28: Why are you adding total to the price of a discounted ticket?

Line 33-34: Why are you asking for age again?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

@WheatFieldOnFire - There is no requirement to use arrays. The only requirement is to calculate a running total of tickets sold.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;

const double TICKET = 5.50;
const double DISCOUNT = 1.08;

int main()
{   int visitors;
    int age;
    double total = 0;
    double price;

    cout << "Please enter the number of visitors: " << endl;
    cin >> visitors;

    for (int i = 1; i <= visitors; i++)
    {   if (i % 5 == 0) // Every 5th ticket is free
        {   cout << "Your ticket is free!" << endl;
            price = 0;
        }
        else 
        {   cout << "Please enter age of visitor: " << endl;
            cin >> age;
            if (age < 5 || age > 65) //find discount is younger than 5 or older than 65
            {   price = TICKET - DISCOUNT;  
                cout << "You get a discount of 1.08 " << price << endl; // calculate discount                
            }                
            else 
                price = TICKET;
        }
        total += price;
    }
    cout << "Total of tickets sold = " << total << endl;
    return 0;
}




Thank you so much for the help got it turned in and working right I did need to add the system ("pause"); at the end cause it kept closing out. I was trying to make it more complicated that it needed to be, but again thank your for the help.
You are right, it is not required, but it is the best to do so you don't have to enter infos a million times if you have a million visitors using this thing.

It is not the "best to do." The same amount of work is required to enter "infos," regardless of whether you store the info in an array or immediately process it. If you're using arrays however, you also have to store all of that info increasing the resources used by (and the complexity of) the program needlessly.
Yes but say we have a million people visiting here and we will use this program to to whatever stuff it can do. from what you say, same amount of work is done, but that is actually not true.

You are correct. The same amount of work is not done. The array version actually requires more work for the bookkeeping inherent in using a dynamically sized array, and of course it also requires more resources as mentioned before. Whether you prompt the user or not for each item of data (which is required by the OP, so not doing so only gains you a failure-to-meet-requirements) is orthogonal to the issue of whether you use an array or not.
Topic archived. No new replies allowed.