最后一行欧普特两个组合输出问题?如果其他语句
Last line ouputs two combined outputs trouble? If else statements
我很难找到为什么我的程序在我的最后一个输出行中输出两次。
如果我尝试5和500的输入,但是当我尝试在第二个输入(例如500000)中使用更大的数字时,我在最后一个输出行中获得了两个不同的输出。
以下是我的代码。我很确定这是我的最后一个话,但我看不到问题。
任何帮助都会非常感谢。
#include <iostream>
using namespace std;
int main()
{
double estimatedSales;
double copyPrice;
double netMade;
double firstOp_net;
double secondOp_net;
double thirdOp_net;
double cashBefore = 5000;
double cashAfter = 20000;
const double FIRST_RATE = .125;
const double SECOND_RATE1 = .10;
const double SECOND_RATE2 = .14;
double bestPrice;
cout << "Enter the price for a copy of your noveln";
cin >> copyPrice;
cout << "Enter the estimated number of copies that will be soldn";
cin >> estimatedSales;
netMade = copyPrice * estimatedSales;
cout << "It is estimated that your novel will generate $" << netMade << " of revenue.n" ;
firstOp_net = cashBefore + cashAfter;
secondOp_net = netMade * FIRST_RATE;
if (estimatedSales <= 4000) {
thirdOp_net = netMade * SECOND_RATE1;
} else {
thirdOp_net = netMade * SECOND_RATE2;
}
cout << "Royalties you keep for Option 1 is $" << firstOp_net <<"n";
cout << "Royalties you keep for Option 2 is $" << secondOp_net <<"n";
cout << "Royalties you keep for Option 3 is $" << thirdOp_net <<"n";
if (firstOp_net > secondOp_net) {
bestPrice = firstOp_net;
} else {
cout<< "Your best bet would be to go with your 2nd Option for $"<< secondOp_net;
}
if (bestPrice > thirdOp_net) {
cout << "Your best bet would be to go with your 1st Option for $"<< firstOp_net;
} else {
cout<< "Your best bet would be to go with your 3rd Option for $"<<thirdOp_net;
}
return 0;
}
这就是我得到的:
Enter the price for a copy of your novel
5
Enter the estimated number of copies that will be sold
500000
It is estimated that your novel will generate $2.5e+06 of revenue.
Royalties you keep for Option 1 is $25000
Royalties you keep for Option 2 is $312500
Royalties you keep for Option 3 is $350000
Your best bet would be to go with your 2nd Option for $312500Your best bet would be to go with your 3rd Option for $350000
这就是我所期望的:
Enter the price for a copy of your novel
5
Enter the estimated number of copies that will be sold
500000
It is estimated that your novel will generate $2.5e+06 of revenue.
Royalties you keep for Option 1 is $25000
Royalties you keep for Option 2 is $312500
Royalties you keep for Option 3 is $350000
Your best bet would be to go with your 3rd Option for $350000
代码的问题是最后一部分的逻辑,同时计算特许权使用费。它实际上是简单的逻辑,您可以减少代码的数量。
这是我的解决方案:
#include <iostream>
using namespace std;
int main()
{
double estimatedSales;
double copyPrice;
double netMade;
double firstOp_net;
double secondOp_net;
double thirdOp_net;
double cashBefore = 5000;
double cashAfter = 20000;
const double FIRST_RATE = .125;
const double SECOND_RATE1 = .10;
const double SECOND_RATE2 = .14;
double bestPrice;
cout << "Enter the price for a copy of your noveln";
cin >> copyPrice;
cout << "Enter the estimated number of copies that will be soldn";
cin >> estimatedSales;
netMade = copyPrice*estimatedSales;
cout << "It is estimated that your novel will generate $" << netMade << " of revenue.n" ;
firstOp_net = cashBefore+cashAfter;
secondOp_net = netMade*FIRST_RATE;
if (estimatedSales <= 4000)
{ thirdOp_net = netMade*SECOND_RATE1;
}
else { thirdOp_net = netMade*SECOND_RATE2;
}
cout << "Royalties you keep for Option 1 is $" << firstOp_net <<"n";
cout << "Royalties you keep for Option 2 is $" << secondOp_net <<"n";
cout << "Royalties you keep for Option 3 is $" << thirdOp_net <<"n";
double big = firstOp_net;
if(big<secondOp_net)
{
big = secondOp_net;
}
if(big<thirdOp_net)
{
big = thirdOp_net;
}
cout << "Your best bet would be to go with your 1st Option for $"<< big;
return 0;
}
相关文章:
- 可能我知道为什么这段代码没有给出任何输出吗?
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 为什么带有逻辑和运算符以及增量运算符的 c++ 程序给出的输出与预期不同?
- C++向量排序给出0作为输出
- 奇怪的数字随机出现在输出中.(C++)
- 如何从Visual Studio中的给出.pyd输出中构造Python代码
- 我将 c++ 矢量数据集转换为 c 数组.我将相同的数据集传递到一个应该给出相同输出的函数中
- 向量<对<双精度,双精度>>给出问题
- 为什么这段代码给出的输出与预期不同?
- C 反向一个不给出预期输出的数组
- 矢量在超出边界时给出0作为输出
- 我很确定我犯了一个愚蠢的错误,但是这段代码给出的输出太长而无法阅读
- C++ 中的侵蚀函数不给出任何输出
- 为什么字符串变量"sum"不存储任何数据,程序不给出任何输出
- 输入层类型:图像数据在窗口咖啡cpp中给出空白输出
- 在队列中,插入和删除后,被删除的元素也会出现在输出中.为什么
- 服务器未收到UDP数据包,花费数小时试图找出问题所在
- 程序给出 0 作为输出 (C++)
- C++ 输出找出问题
- 在成功运行10小时后,在发布模式下从windows应用程序中获得异常,如何检测出问题