C++ data validation not working properly and PDB error?

0

Evening everyone.

I have a program that is meant to have a ticket price and and have parent and child fundraisers to discount the ticket. The program is simple enough, but I'm also supposed to have data validation that makes sure the user only enters 20, 25, or 30 for ticket price. Otherwise, the program gives a chance to re-enter. However, when I run the program, it returns an error no matter what I enter, even if it's the right numbers. Also, if I happen to comment out the loop, it runs fine, but closes on it's own and says this:

'High School Dance.exe': Loaded 'C:\Users\Shaidi\Documents\Visual Studio 2010\Projects\High School Dance\Debug\High School Dance.exe', Symbols loaded.
'High School Dance.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'High School Dance.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'High School Dance.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'High School Dance.exe': Loaded 'C:\ProgramData\Norton\{0C55C096-0F1D-4F28-AAA2-85EF591126E7}\NIS_20.2.0.19\Definitions\BASHDefs\20130412.001\UMEngx86.dll', Cannot find or open the PDB file
'High School Dance.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'High School Dance.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The thread 'Win32 Thread' (0xa5c) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x304c) has exited with code -1073741510 (0xc000013a).
The program '[10896] High School Dance.exe: Native' has exited with code -1073741510 (0xc000013a).

Can anyone help? Here is the program:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

//Prototypes
void studentTicket (void);
void parentFund(void);
void childFund(void);
void totalCosts(void);
void displayTotal (void);
void highestCost (void);
void process (void);

//Global Variables
double ticketPrice, candySold, magsSold, parentDiscount = 0, studentDiscount = 0,     schoolCost = 0;

int main(void)
{
    process();
    return 0;
}

void process(void){
    studentTicket();
    parentFund();
    childFund();
}

void studentTicket(void){
    double ticketPrice;
    cout << "How much does the ticket cost?" <<endl;
    cin >> ticketPrice;

    cout << endl;

    while (ticketPrice != 20 || ticketPrice != 25 || ticketPrice != 30){
        cout << "Invalid amount. A ticket can only cost $20, $25, or $30. Please re-enter a valid amount: " <<endl;
        cin >> ticketPrice;
    }

}

void parentFund(void){

    cout << "How many magazines did the parent sell?" <<endl;
    cin >> magsSold;

    if (magsSold >= 0 && magsSold <= 9){
        parentDiscount = 0;
    } else if (magsSold >= 10 && magsSold <= 15){
        parentDiscount = ticketPrice * .05;
    } else if (magsSold >= 16 && magsSold <= 30){
        parentDiscount = ticketPrice * .15;
    } else if (magsSold >= 31 && magsSold <= 49){
        parentDiscount = ticketPrice * .30;
    } else if (magsSold >= 50){
        parentDiscount = ticketPrice * .50;
    } else {
        cout << "The value entered in invalid." << endl;
    }
    cout <<endl;
    cout << "****************************************************************" <<endl;
    totalCosts();
    cout << "****************************************************************" <<endl;
}

void childFund(void){

    string studentName;
    cout << endl;
    cout << "****************************************************************" <<endl;

    cout << "Enter the student name: " <<endl;
    cin >> studentName;

    cout << endl;
    cout << "How many candies did " <<studentName << " sell?" <<endl;
    cin >> candySold;

    if (candySold > 50){
        studentDiscount = (candySold - 50) * .25;
        studentDiscount += candySold * 15;
    } else  if (candySold >= 1 && candySold <= 50){
        studentDiscount = candySold * .15;
    } else {
        cout << "The number entered is invalid. Please try again." <<endl;
    }
    cout << "****************************************************************" <<endl;
    cout << endl;
    cout << "****************************************************************" <<endl;
    totalCosts();
    cout << "****************************************************************" <<endl;
}

void totalCosts (void){
    schoolCost = studentDiscount + parentDiscount;
    cout << "Parent Cost: " << ticketPrice - parentDiscount << endl;
    cout << "Student Cost: " << ticketPrice - studentDiscount << endl;
    cout << "School Cost: " << schoolCost << endl;

}
c++
runtime-error
validation
pdb
asked on Stack Overflow Apr 23, 2013 by tserran • edited Apr 23, 2013 by WhozCraig

1 Answer

3
while (ticketPrice != 20 || ticketPrice != 25 || ticketPrice != 30){
    cout << "Invalid amount. A ticket can only cost $20, $25, or $30. Please re-enter a valid amount: " <<endl;
    cin >> ticketPrice;
}

Whatever the ticket price is, at least two of those clauses will be true. If it's 20, it's not 30. If it's 25, it's not 20. So at least two of those three will always be true, hence the OR clause as a whole will always be true. So your code is the same as:

while (true){
    cout << "Invalid amount. A ticket can only cost $20, $25, or $30. Please re-enter a valid amount: " <<endl;
    cin >> ticketPrice;
}

And clearly you can never exit this while loop.

answered on Stack Overflow Apr 23, 2013 by David Schwartz

User contributions licensed under CC BY-SA 3.0