如何使程序确定最大的用户输入

时间:2014-04-18 00:42:05

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

所以我的任务是编写一个程序,确定公司四个部门中哪个部门的销售额在四分之一时最高。我基本上有一个问题,我的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语句中,这完全搞砸了所有内容。希望有人能够指导我朝着正确的方向前进。

1 个答案:

答案 0 :(得分:1)

试试这个

string location = "Northwest";
      ^^
      no const