我的代碼有問題。所以,我的功課問這個: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