我的代码有问题。所以,我的功课问这个:C++。程序在输入后保持退出
移动电话服务提供RHAS为客户三个不同的包月套餐:
套餐A:对于每月$ 39.99提供450分钟。额外的分钟是每分钟0.45美元。
套餐B:每月59.99美元,提供900分钟。额外的分钟是每分钟0.40美元。
包C:为每月69.99美元提供无限分钟提供。
编写一个计算客户每月账单的程序。它应该询问客户购买了哪个包裹以及使用了多少分钟。它应该显示应付的总金额。
输入验证:确保用户只选择套餐A,B或C.
这是我的代码吧:
/*
1. Set variables (chars, int, etc) for hours and fees.
2. Ask user to select between A, B, or C.
3. Ask user to input time.
Also set a maximum amount of time for each case and setting a maximum amount of time for the month.
5.Use case switch for options
6.calculate the customers bill for the month apprioprately.
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const double packageA = 39.99;//set variables for all three. They don't change.
const double packageB = 59.99;
const double packageC = 69.99;
char choices = ' '; // use "char" for the packages(choices)
int time = 0; // set time as integer. Since some may be decimals, I use double.
double letter = 0.0; //use "letter" for whatever letter they choose.
cout << "Read choices below and select choice."<<endl;
cout << "A.$39.99 per month gets 450 minutes. Additional minutes are $0.45 per minute." << endl;
cout << "B.$59.99 per month gets 900 minutes. Additional minutes are $0.40 per minute." << endl;
cout << "C.$69.99 per month gets you unlimited access" << endl;
cout << "Select A, B, or C" << endl;
cin >> letter;
if (choices == 'A' || choices == 'B' || choices == 'C')//using switch case
{
cout << "Enter minutes:" << endl;//ask user to input time
cin >> time;
if (time>0 && time<43829)// 43829 is the max amount of minutes in a month. 0 is the least they person can have. If it fits the requirements, then it can continue.
{
switch (choices)
{
case 'A':
if (time<450)
letter = packageA;// if the time is less than required. Then no extra charge.
else
letter = ((time - 450)*0.45) + packageA;// if it exceeds maximum minutes and 45 cents is charged. Same for all cases below except its respective amount is charged.
break;
case 'B':
if (time<900)
letter = packageB;
else
letter = ((time - 900)*.40) + packageB;
break;
case 'C':
letter = packageC;// if not, then package C and no equation since time is unlimited. It is a one time fee for all time used.
break;
default: cout << "Total amount due is: $" << letter << endl; // give total amount charged based on information entered.
}
}
system("pause");
return 0;
}
}
我的问题是,当我运行它,它会在我选择一封信后关闭。如果我选择A,它会自动关闭。关闭后我收到以下消息:
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Users \ Prince \ Documents \ Visual Studio 2013 \ Projects \ ConsoleApplication7 \ Debug \ ConsoleApplication7.exe'。符号加载。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Windows \ SysWOW64 \ ntdll.dll'。找不到或打开PDB文件。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Windows \ SysWOW64 \ kernel32.dll'。找不到或打开PDB文件。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Windows \ SysWOW64 \ KernelBase.dll'。找不到或打开PDB文件。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Program Files \ Bitdefender \ BitDefender 2015 \ active virus control \ Avc3_00259_008 \ avcuf32.dll'。找不到或打开PDB文件。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Windows \ SysWOW64 \ msvcp120d.dll'。找不到或打开PDB文件。
'ConsoleApplication7.exe'(Win32):Loaded'C:\ Windows \ SysWOW64 \ msvcr120d.dll'。找不到或打开PDB文件。
程序'[3476] ConsoleApplication7.exe'已退出,代码为0(0x0)。
难道你不想'cin >>选择'? – quantdev 2014-09-24 05:17:07
听起来好像是时候学习使用调试器了。 – Biffen 2014-09-24 05:17:28
错误消息表明您的防病毒软件也可能会造成干扰,请尝试将其关闭 – 2014-09-24 05:37:33