好的,这是一个由于输出反向显示而被扣除的分配。我应该提示用户输入,然后按降序显示输入,但我遇到了显示问题。我有两个数组,一年[]来保存月份和一个month[totalMonths]
来保存用户输入。当我排序和显示输入year[]
不符合月份,它是固定的。例如,如果用户在Jan输入1,在Feb输入2,在Mar输入3,则显示为; 扬:3 月:2 三月:1排序输入反向工作
如何我能得到个月与对显示其应有的输入对应任何想法?这里是排序和显示功能:
void sortArray(double month[], string year[], int totalMonths)
{
int temp;
bool swap;
do
{
swap = false;
for(int count = 0; count < totalMonths - 1; count++)
{
if(month[count] < month[count + 1])
{
temp = month[count];
month[count] = month[count + 1];
month[count + 1] = temp;
swap = true;
}
}
} while(swap);
cout << "------------------------------------------------------------" << endl;
cout << "Here are the months rainfall statistics sorted from highest to lowest: " << endl;
for (int index = 0; index < totalMonths; index++)
cout << year[index] << "\t " << setw(5) << month[index] << endl;
}
这里是我的string year[]
定义:
string year[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
我suppost你的年数组包含诸如:{“jan”,“feb”,“mar”,...}?你可以打印你的年份表定义plz – grifos 2012-03-26 16:32:56
我刚在我的文章中更新了我的年份[]定义。 – Gmenfan83 2012-03-26 16:35:23
这将最大的元素放在顶部;当你交换你应该交换的月份和年份(以及任何其他领域你绑在一起) – Adrian 2012-03-26 17:02:37