【问题标题】:How to make program determine largest user input如何使程序确定最大的用户输入
【发布时间】:2014-04-18 00:42:05
【问题描述】:

所以我的任务是编写一个程序来确定公司四个部门中哪个部门在一个季度的销售额最高。我基本上对我的 cout 语句没有吐出位置有疑问。这是我所拥有的: 函数原型:

double getSales(string const);
void findHighest(double, double, double, double);

main(不能碰教官命令):

//variables
    double nwSales, neSales, swSales, seSales, highest; 
    string const NW = "Northwest",
                 NE = "Northeast",
                 SW = "Southwest", 
                 SE = "Southeast"; 

    cout << fixed << showpoint << setprecision(2);

    nwSales = getSales(NW); // these are calls to a function that returns a value
    neSales = getSales(NE);
    swSales = getSales(SW);
    seSales = getSales(SE); 
    findHighest(nwSales,neSales,swSales,seSales); 

函数定义:

double getSales(string const location)
{
    double sales;
    cout << "The " << location <<" branch had a quarterly sales figure of: $ ";
    cin >> sales;
    cout << "\n";
    while (sales < 0)
{
        cout << over3 << sales << " is not valid! Try again: "; 
        cin >> sales;
}
    return sales;
}

我很确定这是对的。我主要是在这部分遇到问题:

void findHighest(double nwSales, double neSales, double swSales, double seSales)
{
system("CLS");
double highest  = nwSales;
string const location = "Northwest";

if (neSales > highest)
{
    highest = neSales;
    location = "Northeast";
}
if (swSales > highest)
{
    highest = swSales;
    location = "Soutwest";
}
if (seSales > highest)
{
    highest = seSales;
    location = "Southeast";
}
cout << down5;
cout << "The highest grossing division was " << location << "with $ " << highest;
cout << down7;

}

我不明白为什么它不告诉我位置。我尝试将 cout 语句放在每个 if 语句 bu 中,这完全搞砸了一切。希望有人能够指导我正确的方向。

【问题讨论】:

  • 如果locationconst,怎么改呢?编译器不是在抱怨吗?
  • 它在抱怨......一秒钟就挂了很多
  • 哇,解决了。非常感谢,我不敢相信这是唯一让我受不了的东西!

标签: c++ function cout function-calls function-prototypes


【解决方案1】:

试试这个

string location = "Northwest";
      ^^
      no const

【讨论】:

  • 如果我有足够的声誉来投票,我会...再次感谢!
  • @user3470987:不客气。如果这个答案有助于解决您的问题,那么您可以“接受”这个答案。点击答案左侧的复选标记即可接受答案。
猜你喜欢
  • 2018-02-23
  • 2023-03-14
  • 1970-01-01
  • 2020-02-10
  • 2018-03-03
  • 2022-01-03
  • 1970-01-01
  • 2018-07-08
  • 2013-05-26
相关资源
最近更新 更多