C++ 电话账单项目:C++;

C++ 电话账单项目:C++;,c++,C++,好的,我已经编辑了一些代码,现在的问题是它如何计算正确的最终总数?我正在使用常规服务,我希望它先减去50分钟的免费时间,然后加上用户过度使用的额外时间,然后将额外时间乘以0.20美元,并计入最终总数。 如果我还有什么错误,请告诉我。我知道我犯了很多错误,对不起! 我有一个项目要做,下面是请求的功能列表: 提示用户输入帐号、服务代码和服务使用的分钟数 常规:值为“R”和“R”: 每月$10.00 前50分钟是免费的 超过50分钟的费用为每分钟0.20美元 溢价:价值为“p”和“p”: 25

好的,我已经编辑了一些代码,现在的问题是它如何计算正确的最终总数?我正在使用常规服务,我希望它先减去50分钟的免费时间,然后加上用户过度使用的额外时间,然后将额外时间乘以0.20美元,并计入最终总数。 如果我还有什么错误,请告诉我。我知道我犯了很多错误,对不起! 我有一个项目要做,下面是请求的功能列表:

  • 提示用户输入帐号、服务代码和服务使用的分钟数

    • 常规:值为“R”和“R”:

      • 每月$10.00
      • 前50分钟是免费的
      • 超过50分钟的费用为每分钟0.20美元
    • 溢价:价值为“p”和“p”:

      25.00美元/月加:

      • 在前75分钟打6-18次电话是免费的,之后是每分钟0.10美元
      • 前100分钟18-6次之间的通话是免费的,之后每分钟0.05美元
  • 如果使用了任何其他字符,则显示错误消息

  • 计算总数并打印账单(显示出来)
这是我的代码:

#include <iostream>

using namespace std;
int main()
{
// VARIABLES //
int accnum, minnum, minnumm;
double total, finaltotal, grandtotal, finaltotall;
char scode;

cout << "Hello, thank you for paying your phone bill." << ends;
cout << endl;
cout << endl;

cout << "Please enter your account number: ";
cin >> accnum ; //Enter some number

cout << "Please enter your service code (r as regular service or p for premium service): ";
cin >> scode ;  //Enter R or r for regular service and P or p for premium service

        ////////////// THIS IS FOR REGULAR SERVICE //////////////

if (scode == 'R' || scode == 'r') {     // Values for Regular service
    cout << "This service provides 50 minutes for phone calls for 50 minutes for free for $10.00 a month, and charge $0.20 every minute over 50 minutes." << endl;
    cout << "How many minutes have you used up?: ";
    cin >> minnum;
    if (minnum > 50) {
        total = minnum * .20;
        finaltotal = total + 10;
        cout << "You have made phone calls over 50 minutes, your total will be " << finaltotal << "." << endl;
        cout << "Your account number is " << accnum << " , with a Regular service. You have used " << minnum << "/50 minutes. Your total is $" << finaltotal << " . Thank you for your time." << endl;    //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
        cout << endl;
    } else {
        cout << "You have not made phone calls over 50 minutes, your total will be $" << finaltotal << "." << endl;
        cout << "Your account number is " << accnum << " , with a Regular service. You have used " << minnum << "/50 minutes. Your total is $" << finaltotal << " . Thank you for your time." << endl; //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
    }

       ////////////// THIS IS FOR PREMIUM SERVICE //////////////

} else if (scode == 'P' || scode == 'p') {  //Values for Premium service
    cout << "This service provides your first 75 minutes phone calls from 6:00 - 18:00, and charge $0.10 for every minute over. Your first 100 minutes for phone calls from 18:00 - 6:00 are free, and charge $0.05 for every minute over." << endl;
    cout << "How many minutes have you used up between 6:00 - 18:00? ";    //Time between 6am - 6pm
    cin >> minnumm;
        if (minnumm > 75) {                  //If # of minutes is over 75
            total = minnumm * .10;           //Then it multiplies total * $.10
            finaltotall = total + 25;   //Then adds the $10/month
            cout << "You have made phone calls over 75 minutes, your total will be $" << finaltotall << "." << endl;
        } else {
            cout << "How many minutes have you used up between 18:00 - 6:00? ";  }   //Time between 6pm - 6am
            cin >> minnum;
        if (minnum > 100) {                 //If # of minutes is over 100
            total = minnum * .05;           //Then it multiplies total * $.05
            finaltotal = total + 25;
            //Then adds the $25/month
            cout << "You have made phone calls over 100 minutes, your total will be $" << finaltotal << "." << endl;

            grandtotal = finaltotall + finaltotal;  //Calculates both the 6am-6pm and 6pm-6am totals together
            cout << "Your account number is " << accnum << " , with a Premium service. You have used " << minnumm << "/75 minutes from 6:00-18:00. You have used" << minnum << "/100 from 18:00-6:00. Your total is $" << grandtotal << " . Thank you for your time." << endl; //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
        } else {
            cout << "You have not made phone calls over 100 minutes, your total will be $" << finaltotal << "." << endl;
            cout << "Your account number is " << accnum << " , with a Premium service. You have used " << minnumm << "/75 minutes from 6:00-18:00. You have used " << minnum << "/100 from 18:00-6:00. Your total is " << grandtotal << " . Thank you for your time." << endl;
            cout << endl;
            cout << endl; } //Displays the acc. #, type of service, # of min the phone service used, and amount due from user

        ////////////// THIS IS IF THEY TYPED IN ANY LETTER OTHER THAN R, r, P, p //////////////

} else {        //If user doesn't type P or R, then this is error message
    cout << "Sorry, that service does not exist. Please try again." << endl;
    cout << endl; }


system("pause");
return 0;
#包括
使用名称空间std;
int main()
{
//变数//
内特阿克努姆、米努姆、米努姆;
双倍总计、最终总计、总总计、最终总计;
字符编码;
cout据我所知(后续回答中的人可能会发现更多错误),突出的问题是您使用了运算符,而不是运算符

本声明:

if (scode == 'R' && scode == 'r') {     // Values for Regular service
if (scode == 'P' && scode == 'p') {  //Values for Premium service
应该是:

if (scode == 'R' || scode == 'r') {     // Values for Regular service
if (scode == 'P' || scode == 'p') {  //Values for Premium service
同样,这项声明:

if (scode == 'R' && scode == 'r') {     // Values for Regular service
if (scode == 'P' && scode == 'p') {  //Values for Premium service
应该是:

if (scode == 'R' || scode == 'r') {     // Values for Regular service
if (scode == 'P' || scode == 'p') {  //Values for Premium service

一个变量不能同时匹配两个不同的值,因此当使用
&&
而不是
|

@Brandon时,将永远不会输入
if
块,因为您应该在询问StackOverflow之前调试代码表达式“A=&&A==”总是假的
scode
双精度
应该是一个
char
。它甚至比这更引人注目。看看
scode
的定义。