我需要一個函數,它將經過下面的值並以其名稱打印出最高值。要找到20的最高值並不難,但我無法找到顯示值名稱的方法。謝謝!以名稱顯示最高值
例子:
North: 5
South: 10
West: 15
East :20
輸出:
Winner is East with $20 in sales!
這是我走到這一步,
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
double northeast, northwest, southeast, southwest;
// Function prototype
double getSales(string);
void findHighest();
int main()
{
northeast = getSales("Northeast");
northwest = getSales("Northwest");
southeast = getSales("Southeast");
southwest = getSales("Southwest");
return 0;
}
//Function getSales
double getSales(string name)
{ cout << "What is the quarterly sales figure for " << name << "? ";
double sales;
cin >> sales;
while (sales < 0)
{
cout << "Please enter a positive value ";
cin >> sales;
}
return sales;
}
// Function getHighest
void getHighest()
{
}
請顯示您到目前爲止的內容。該解決方案可能是對現有代碼的直接修改。 – 2012-02-23 04:50:46
數值如何存儲?一個'map'? –
2012-02-23 04:50:56
你想做什麼?清楚。 – 2012-02-23 04:52:15