Setting parameters on command line?

Hey everyone, I'm fairly new to C++ and have been given an assignment for my class. My professor isn't that good at explaining the material so I'm a bit lost. The prompt I have is to enter destinations and passengers into the command line "FileName Location Passengers Passenger_Number" so for example "Travel MIAMI Passengers 5". This will in turn notify me of the price to fly to each destination depending on the location and the number of passengers. The requirements are:
1. You can have a maximum of 5 locations, and a minimum of 1.
2. Passengers input is required. At least 1. No maximum.
3. If any location codes are unknown, please exit the application

I have everything running the way it should, the only problem I am encountering, is the max and min of the locations. For example, I can get "FileName Location Location Location Location Location Passengers PassengerNumber" to work, however I don't know how to make it work if I only input 1-4 locations rather than 5. I was told I have to create a for loop? Does anyone know how I can apply this to my assignment?
#include<iostream>
#include<string>

using namespace std;

int main(int parameterCount, char* inputs[]){
string input1 = inputs[1];
string input2 = inputs[2];
string input3 = inputs[3];
string input4 = inputs[4];
string input5 = inputs[5];
int passenger = atoi(inputs[7]);
int location[5];
bool direction1 = true;
bool direction2 = true;
bool direction3 = true;
bool direction4 = true;
bool direction5 = true;

while (direction1){
if(input1 == "MIAMI" || input1 == "Miami"){
direction1 = false;
location[1] = 250;
}else if(input1 == "HAWAII" || input1 == "Hawaii"){
direction1 = false;
location[1] = 300;
}else if(input1 == "LA"){
direction1 = false;
location[1] = 200;
}else if(input1 == "NY"){
direction1 = false;
location[1] = 275;
}else if(input1 == "SEATTLE" || input1 == "Seattle"){
direction1 = false;
location[1] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}
while (direction2){
if(input2 == "MIAMI" || input2 == "Miami"){
direction2 = false;
location[2] = 250;
}else if(input2 == "HAWAII" || input2 == "Hawaii"){
direction2 = false;
location[2] = 300;
}else if(input2 == "LA"){
direction2 = false;
location[2] = 200;
}else if(input2 == "NY"){
direction2 = false;
location[2] = 275;
}else if(input2 == "SEATTLE" || input2 == "Seattle"){
direction2 = false;
location[2] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}
while (direction3){
if(input3 == "MIAMI" || input3 == "Miami"){
direction3 = false;
location[3] = 250;
}else if(input3 == "HAWAII" || input3 == "Hawaii"){
direction3 = false;
location[3] = 300;
}else if(input3 == "LA"){
direction3 = false;
location[3] = 200;
}else if(input3 == "NY"){
direction3 = false;
location[3] = 275;
}else if(input3 == "SEATTLE" || input3 == "Seattle"){
direction3 = false;
location[3] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}
while (direction4){
if(input4 == "MIAMI" || input4 == "Miami"){
direction4 = false;
location[4] = 250;
}else if(input4 == "HAWAII" || input4 == "Hawaii"){
direction4 = false;
location[4] = 300;
}else if(input4 == "LA"){
direction4 = false;
location[4] = 200;
}else if(input4 == "NY"){
direction4 = false;
location[4] = 275;
}else if(input4 == "SEATTLE" || input4 == "Seattle"){
direction4 = false;
location[4] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}
while (direction5){
if(input5 == "MIAMI" || input5 == "Miami"){
direction5 = false;
location[5] = 250;
}else if(input5 == "HAWAII" || input5 == "Hawaii"){
direction5 = false;
location[5] = 300;
}else if(input5 == "LA"){
direction5 = false;
location[5] = 200;
}else if(input5 == "NY"){
direction5 = false;
location[5] = 275;
}else if(input5 == "SEATTLE" || input5 == "Seattle"){
direction5 = false;
location[5] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}

float ticketTotal = (location[1] + location[2] + location[3] + location[4] + location[5])*passenger;
float fees = (ticketTotal*.10);
float subtotal = fees + ticketTotal;
float discount = (subtotal*.10);
float taxes = .15*(subtotal);
float total = subtotal + taxes;
float totalPrice = subtotal - discount + taxes;
string discountCode;

bool off = true;

cout << "Greetings! Thank you for choosing LinAppleSoft Travel. You have chosen the following locations:" << endl;
cout << "Location: " << input1 << " - $" << location[1] << endl;
cout << "Location: " << input2 << " - $" << location[2] << endl;
cout << "Location: " << input3 << " - $" << location[3] << endl;
cout << "Location: " << input4 << " - $" << location[4] << endl;
cout << "Location: " << input5 << " - $" << location[5] << endl;
cout << "Number of tickets: " << passenger << endl;
cout << "Ticket total: $" << ticketTotal << endl;
cout << "Fees: $" << fees << endl;
cout << "Subtotal: $" << subtotal << endl;
cout << "Taxes: $" << taxes << endl;
cout << "Total: $" << total << endl;
cout << "Do you have any coupon codes? If so, please type it in, or say no." << endl;
cin >> discountCode;
while(off){
if (discountCode == "LINAPPLESOFT"){
off = false;
}else if(discountCode == "NO" || discountCode == "no" || discountCode == "No"){
cout << "Then your total remains $" << total << endl;
cout << "Bon Voyage!" << endl;
cin.ignore();
cin.get();
return 0;
}else{
cout << "Not a valid input, please try again" << endl;

}
}
cout << "Thank you, your total has been reduced by 10%." << endl;
cout << "Revised Total: $" << totalPrice << endl;
cout << "Bon Voyage!" << endl;

cin.ignore();
cin.get();
return 0;
}
Can you post your code to show us what you have tried?
yeah, so the above is what my assignment looks like so far. to correct my current issue, I tried to do a for function for every if functions. so
for(int i = 0; i < 8; i++){
while (direction1){
if(input1 == "MIAMI" || input1 == "Miami"){
direction1 = false;
location[1] = 250;
}else if(input1 == "HAWAII" || input1 == "Hawaii"){
direction1 = false;
location[1] = 300;
}else if(input1 == "LA"){
direction1 = false;
location[1] = 200;
}else if(input1 == "NY"){
direction1 = false;
location[1] = 275;
}else if(input1 == "SEATTLE" || input1 == "Seattle"){
direction1 = false;
location[1] = 280;
}else{
cout << "I'm sorry, but you have input an invalid location. Please check your spelling, and try again" << endl;
return 0;
}
}
and then for the next if function I would just do for(int i = 0; i < 7; i++)
and keep doing that till I got to i < 4 and stopped
This is what the assignment prompt looks like:


Assignment:
LinAppleSoft has received a contract for a travel agency. They've asked for an itinerary application to price out travel plans for new customers.
Create an application that does the following:

receives a list of location code inputs in the command line
receives a passenger count in the command line
tallies up the flight plan cost
applies taxes
asks for a coupon code. If LINAPPLESOFT in given, and applies a 10% discount
Command line input should be formatted like this:

> TravelAgent {LOCATION CODES} Passengers PASSENGER_COUNT 
Example:

> TravelAgent MIAMI HAWAII Passengers 4

====================================
Output:
The client is picky. Output should look EXACTLY like the following:
> TravelAgent MIAMI HAWAII Passengers 4
Greetings! Thank you for choosing LinAppleSoft Travel. You have chosen the following locations:

Location: Miami - $250
Location: Hawaii - $300
Number of tickets: 4

Ticket total: $2200

Fees: $220
Subtotal: $4420.00
Taxes: $663.00
----------------------------
Total: $5083.00

Do you have any coupon codes?

> LINAPPLESOFT

Thank you, your total has been reduced by 10%.

Revised Total: $4574.70

Bon Voyage!

====================================
Pricing:
Location
Location Code
Price
Miami
MIAMI
$250
Hawaii
HAWAII
$300
Los Angeles
LA
$200
New York
NY
$275
Seattle
SEATTLE
$280

Ticket total: sum of all ticket prices * passenger count
Fees: 10% of Ticket total
Subtotal: Fees + ticket total.
Discount: 10% of subtotal
Taxes: 15% of (subtotal - discount)
Total price: subtotal - discount + taxes
 
Revised total: total price - discount.

====================================

Requirements:

1. You can have a maximum of 5 locations, and a minimum of 1.
2. Passengers input is required. At least 1. No maximum.
3. If any location codes are unknown, please exit the application.

====================================
HINTS:

1. Passenger count will always be the last input on the command line.
2. Given the command line input format, the location list on the command line will always be from index[1] to index [parameterCount - 3];
Topic archived. No new replies allowed.