Help Needed: For loop with array?

Hi all,
Going straigt to the point here: This is what my end goal / prompt I need to achieve.

I have a project where it involves a set number of passengers. When passenger number reach 210 it will be need to increment by 10 until 500. As that happens with every increment the price of the ticket discounts by 00.50 every 10 increments. The base price is at $30.00 for passengers in quanitty of 209 and less.

The question is the passnger number will increment and then the price will be discounted. Is there a way to use a array to store the passenger values and the corresponding price so that it can be accessd and then COUT the matching numbers. To give the user the amount he entered in passenger and then COUT the matching price. Thanks for reading and sorry for any poor programming.




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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 #include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
    int minpass;            // Minimum Passengers                               // Can NOT exceed 500 passengers
    int maxpass;            // Maximum Passengers       // <--- User Inputs
    int fixcost;            // Fixed Cost                                       // Can NOT exceed 500 passengers
    float tickcost;
    float price = 30.00;
    float minprofit = 14.00;




    cout << "Please enter the minimum amount of passengers: ";              // User enters the amount of desired MINIMUM  of passengers
    cin >> minpass;

        if ( minpass > 500 )                // IF statement to make sure the minimum amount of passengers does not EXCEED 500
        {
            cout << "You have exceeded the maximum amount of 500 passengers." << endl << endl;              // COUT gives users warning that they have exceeded the MAXIMUM amount of passengers
            return main();              // If the amount of exceed the MAX then the user will be returned to enter another amount
        }

            if ( minpass < 1 )              // IF statement to make sure the minimum amount is NOT less than 1
            {
                cout << "You did not meet the minimum amount of passengers." << endl << endl;               // COUT give users warning that the amount of passengers have not met the MINIMUM amount
                return main();              // IF  the amount is less than the minimum then user will be returned to enter another amount
            }


                if ( minpass <= 209)
                {
                    tickcost = minpass * price;
                    cout << "Total cost of " << minpass << " tickets at $30.00 comes to: $" << tickcost << endl;


                }






               for ( minpass >= 210; minpass <= 500; minpass+=10)                   // IF the minpass is equal or greater than 210 it will increment by 10

                   cout << minpass << endl;
                   for (price = price; price >= minprofit; price -=.50)
                   cout<< price << fixed << setprecision(2) << endl;

}
Last edited on
Line 23, 29: It's not permitted to recursively call main().

Line 46: The initialization term of the for statement is a condition, not an initialization.

Line 49: The initialization term doesn't do anything. You can just omit it.

Line 50: What's the point of the fixed and setprecision AFTER outputting the price?

Topic archived. No new replies allowed.