0

In my function definitions under apply_discount, when I enter a 1 or 2 for the discountQues to see if the customer has a coupon, the program thinks I'm entering a ticket type (1=toddler, 2=junior, 3=senior). Can you tell me what I'm doing wrong? I already tried making discountQues a global variable, but that didn't help. I also tried moving the discount question code into main and that got me nowhere as well. The code is supposed to process a formula when I enter whether or not the customer has a discount coupon. Instead, it asks me to enter in the number of tickets again.

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <locale>

using namespace std;

//function prototype
double get_ticket_type();
double find_ticket_price(double ticType);
double apply_discount(double price, double ticType);
void disp_purchase();
void disp_final_report ();

const double  JUNIOR_TIC_PRICE       = 7.50; 
const double  SENIOR_TIC_PRICE       = 11.50;
const double  TODDLER_TIC_PRICE      = 0.0;
const double  DISCOUNT               = 0.25;
const double  MAX_SEAT_COUNT         = 10.0;
      double  discountQues           = 0.0;

int main()

{
    //declare variables

    double        discountQues           = 0.0;
    double        extraTic               = 0.0;
    double        juniorTicTotal         = 0.0;
    double        numTic                 = 0.0;
    double        seniorTicTotal         = 0.0;
    double        ticType                = 0.0;
    double        toddlerTicTotal        = 0.0;
    double        totalCost              = 0.0;
    double        totalNumTic            = 0.0;
    double        totalRevenue           = 0.0;
    double        discountPrice          = 0.0;

    //welcome the user and explain the purpose of the software
    int consoleWidth = 40;
    std::cout << setw(consoleWidth / 2) << " " << "       PRIOLEAU PROGRAMMING, INC  " << endl;
    std::cout << setw(consoleWidth / 2) << " " << "SUMMERVILLE SEAWORLD TICKETING SOFTWARE 1.0" << endl << endl;
    std::cout << "This program is designed to control, manage and track "
    "ticket sales for Summerville Seaworld. Please input information when "
    "you are prompted." << endl << endl;    

    //choose a type of ticket
    ticType = get_ticket_type();//call function to get ticket type

    while (ticType == 1 || ticType == 2 || ticType == 3 && ticType != 4)
    {   

    //find ticket price
    double price = find_ticket_price(ticType);

    //receive ticket cost, apply discount and return discounted cost
    discountPrice = apply_discount(price, ticType);

    //display final report once all seats are sold
    disp_final_report ();

    //display purchase information for 1 completed sale
    disp_purchase();

    }   //end while

    //choose a type of ticket
    double get_ticket_type(double ticType);

    //find ticket price
    double find_ticket_price(double ticType, double TODDLER_TIC_PRICE, 
        double JUNIOR_TIC_PRICE, double SENIOR_TIC_PRICE);

    while (ticType == 4)
    {//while ticket type is toddler
        extraTic = MAX_SEAT_COUNT -totalNumTic;

    //display final report
    disp_final_report ();

    std::cout << endl;
    system("pause");
    return 0;
    }//end while

    std::cout << endl;
    system("pause");
    return 0;
}   //end of main function

//*****function definitions*****
double get_ticket_type()
{
    double ticType; 
    std::cout << "Please select from the following types of tickets: " << endl << endl;
    std::cout << "NUMBER   TICKET TYPE   AGE RANGE   COST" << endl;
    std::cout << "1        Toddler       0-5 years   Free" << endl;
    std::cout << "2        Junior        6-16 years  $7.50" << endl;
    std::cout << "3        Senior        17 and up   $11.50" << endl;
    std::cout << "4        Quit Program" << endl;
    std::cout << endl << endl;

    std::cout << "Which type of ticket would you like to purchase? Enter "
    "1, 2 or 3 to purchase tickets. Enter 4 to Quit:" << endl;
    std::cin >> ticType;
    return ticType;
    std::cout << endl;
}   //end of get_ticket_type function

double find_ticket_price(double ticType)
{
    if (ticType == 1)
    {//if purchase toddler ticket
        std::cout << fixed << setprecision(2);
        std::cout << "You have selected to purchase a Toddler ticket. "
        "Toddler tickets are $" << TODDLER_TIC_PRICE << " each. ";
        return TODDLER_TIC_PRICE;
    }

    else if (ticType == 2)
    {//if purchase junior ticket
        std::cout << fixed << setprecision(2);
        std::cout << "You have selected to purchase a Junior ticket. "
        "Junior tickets are $" << JUNIOR_TIC_PRICE << " each. ";
        return JUNIOR_TIC_PRICE;
    }

    else if (ticType == 3)
    {//if purchase senior ticket
        std::cout << fixed << setprecision(2);
        std::cout << "You have selected to purchase a Senior ticket. "
        "Senior tickets are $" << SENIOR_TIC_PRICE << " each. ";
        return SENIOR_TIC_PRICE;
    }
    else;
}   //end find_ticket_price

double apply_discount(double price, double ticType)
{
    double numTic = 0.0;
    double discountQues = 0.0;
    double totalRevenue = 0.0;
    double totalCost = 0.0;
    double discountPrice = 0.0;
    double totalNumTic = 0.0;
    double toddlerTicTotal = 0.0;
    double juniorTicTotal = 0.0;
    double seniorTicTotal = 0.0;

    if (ticType == 1)
    {//if purchase toddler ticket
        std::cout << "How many Toddler tickets would you like to buy?";
        std::cout << " Please enter the number of tickets (1-10): " << endl;
        std::cin >> numTic;
        std::cout << endl;
    }   

    if (numTic > 0 && numTic <= 10)
    {//if number of toddler tickets is between 1-10
        std::cout << "Do you have a discount coupon today?" << endl;
        std::cout << "Enter 1 for YES or 2 for NO: " << endl;
        std::cin >> discountQues;
        std::cout << endl;
    }
        else
        {//else the number of tickets is not between 1-10
            std::cout << "The maximum number of tickets that can be sold "
            " is 10. Please enter a number between 1-10." << endl;
            std::cin >> numTic;
            std::cout << endl;
        }
            if (discountQues == 1 && ticType == 1)
            {//if customer has a discount coupon
                totalCost = TODDLER_TIC_PRICE * numTic;
                discountPrice = totalCost - (totalCost * DISCOUNT);
            }

            else
            {//else the customer does not have a discount coupon
                totalCost = TODDLER_TIC_PRICE * numTic;
            }

    //counter and accumulator
    totalNumTic += numTic;
    totalRevenue += totalCost;
    toddlerTicTotal += totalNumTic;

    /*
    if (ticType == 2)
    {//if purchase junior ticket
        std::cout << "You have selected to purchase a Junior ticket. "
        "How many Junior tickets would you like to buy?"
        " Please enter the number of tickets (1-10): " << endl;
        std::cin >> numTic;
        std::cout << endl;
    }
    else if (numTic > 0 && numTic <= 10)
    {//if number of junior tickets is between 1-10
        std::cout << "Do you have a discount coupon today?" << endl;
        std::cout << "Enter 1 for YES or 2 for NO: " << endl;
        std::cin >> discountQues;
        std::cout << endl;
    }       
    else
    {//else the number of tickets is not between 1-10
        std::cout << "The maximum number of tickets that can be sold "
        " is 10. Please enter a number between 1-10." << endl;
        std::cin >> numTic;
        std::cout << endl;
    }
        if (discountQues == 1 && ticType == 2)
        {//if customer has a discount coupon
            totalCost = JUNIOR_TIC_PRICE * numTic;
            discountPrice = totalCost - (totalCost * DISCOUNT);
        }

        else
        {//else the customer does not have a discount coupon
            totalCost = JUNIOR_TIC_PRICE * numTic;
        }

    //counter and accumulator
    totalNumTic += numTic;
    totalRevenue += totalCost;
    juniorTicTotal += totalNumTic;

    if (ticType == 3)
    {//if purchase senior ticket
        std::cout << "You have selected to purchase a Senior ticket. "
        "How many Senior tickets would you like to buy?"
        " Please enter the number of tickets (1-10): " << endl;
        std::cin >> numTic;
        std::cout << endl;

        if (numTic > 0 && numTic <= 10)
        {//if number of senior tickets is between 1-10
            std::cout << "Do you have a discount coupon today?" << endl;
            std::cout << "Enter 1 for YES or 2 for NO: " << endl;
            std::cin >> discountQues;
            std::cout << endl;
        }

        else
        {//else the number of tickets is not between 1-10
            std::cout << "The maximum number of tickets that can be sold "
            " is 10. Please enter a number between 1-10." << endl;
            std::cin >> numTic;
            std::cout << endl;
        }
            if (discountQues == 1 && ticType == 3)
            {//if customer has a discount coupon
                totalCost = SENIOR_TIC_PRICE * numTic;
                discountPrice = totalCost - (totalCost * DISCOUNT);
            }
            else
            {//else the customer does not have a discount coupon
                totalCost = SENIOR_TIC_PRICE * numTic;
            }
    }

    //counter and accumulator
    totalNumTic += numTic;
    totalRevenue += totalCost;
    seniorTicTotal += totalNumTic;
    */
    return discountPrice;

}   //end apply_discount

Edited by andigirlsc: Unnecessary code included

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by deepecstasy
0

My love, you are trying to call the functions which you have not defined, you are trying to call just the prototype of function. So just comment

//void disp_final_report();

&

//void disp_purchase();

Then in all other functions where you are calling them, comment the call, like in main func at line 81.

I suggest you to just give the definition of disp func() & get away with all the hassle.

Also update yourself to use Visual Studio 2008 or 2010. In them there is no need to write std:cin/cout, just

#include <iostream> 
using namespace std; 

& make your life easy!

Edited by deepecstasy

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.