如何使程序停止出现构建问题并停止使用负数?

问题描述

我的程序需要能够计算每月的电话费,并且有3个计划:10小时免费且收费9.95的基本服务,20小时免费并收费14.95的金卡服务以及白金服务,您无限制的小时它的价格为19.95。当我的程序的小时数少于免费小时数时,它会从初始成本中减去这些小时数,并且还有构建小时数。

  #include <iostream>
#include <string>
using namespace std;

int main()
{
    //Set up the variables.
    string input;
    int hours;
    int basicHours;
    int goldHours;
    float extraBasic;
    float basicCost;
    float goldCost;

    // Will ask and display the user their plan and hours.
    cout << "Hello! Welcome to the Comms4You Telecom Company!" << endl;
    cout << "Please provide your plan." << endl;
    cin >> input;
    cout << input << ",Ok now please provide the amount of hours you used." << endl;
    cin >> hours;
    //Calculate different equations
     basicHours = (hours - 10);
     goldHours = (20 - hours);
     extraBasic = (basicHours * 2);
     basicCost = (9.95 + extraBasic);
     goldCost = (14.95 + goldHours);
    //This part is for displaying to the users plans and hours.(Also calculations)
     if (input == "Platinum") {
         cout << "Our company thanks you for using " << hours << " hours! " << "Your total cost is $19.95.";
     }
     else if (input == "Gold") {
         cout << "Our company thanks you for using " << hours << " hours! " << "Your total cost is $" << goldCost << ".";
     }
     else if (input == "Basic") {
         cout << "Our company thanks you for using " << hours << " hours! " << "Your total cost is $" << basicCost << ".";
     }
     else
        return 0; 

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)