C++ 数据验证工作不正常和 PDB 错误?

标签 c++ validation runtime-error pdb-files

大家晚上好

我有一个计划,该计划旨在提供票价,并让家长和 child 筹款人为门票打折。该程序非常简单,但我还应该进行数据验证,以确保用户只输入 20、25 或 30 作为票价。否则,程序会提供重新输入的机会。但是,当我运行该程序时,无论我输入什么,它都会返回一个错误,即使它是正确的数字。此外,如果我碰巧注释掉循环,它运行良好,但会自行关闭并说:

'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).

有人可以帮忙吗?这是程序:

#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;

}

最佳答案

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;
}

无论票价是多少,至少有两个条款是正确的。如果是 20,则不是 30。如果是 25,则不是 20。因此,这三个中至少有两个将始终为真,因此 OR 子句作为一个整体将始终为真。所以你的代码是一样的:

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

显然,您永远无法退出此 while 循环。

关于C++ 数据验证工作不正常和 PDB 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16161024/

相关文章:

c++ - 在特定时间淡入和淡出对象

c++ - 哪个是最可靠的分析工具 gprof 或 kcachegrind?

jquery - 如何阻止 jQuery validate 自动验证?

c# - 在 ViewModel 实体上使用 DataAnnotation 进行 Prism IDataErrorInfo 验证

ruby-on-rails - 仅在生产环境中添加验证错误

c++ - HWLOC 链接错误

c++ - 从微秒构建 boost::posix_time::time_duration

c++ - 制作不同子类实例的 vector

java - logback 资源 [logback.xml] 上出现错误而不是警告 在类路径上多次出现

c - 对变量和常量的操作在c中给出不同的结果