4

我是 C++ 新手,找不到任何解决此错误的方法。据我所知,我没有重载任何变量来与命名产生冲突(这是我在网上找到的最接近原因的事情)。任何帮助将非常感激。

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int getNumAccidents(string);
int findLowest(int accidents[]);
int main()
{
 const int ARRAY_SIZE = 5;
 int input;
 int accidents[ARRAY_SIZE];
 int counter = 0;
 string regions[ARRAY_SIZE] = {"North", "South", "East", "West", "Central"};
 string name;
 string lowestRegion;
 int lowest = 1000000000;
 while (counter < ARRAY_SIZE)
 {
  name == regions[counter];
  accidents[counter] = getNumAccidents(name);
  counter++;
 }
 findLowest(accidents);
 system("PAUSE");
 return 0;
}

int getNumAccidents(string name)
{
 int input;
 validate:
 cout<<"Enter the number of accidents that took place in the "<<name<<" region in the                  last year:"<<endl;
 cin>>input;
 if (input < 0)
 {
  system("CLS");
  cout<<"Invalid input: the number of accidents can not be negative.";
  goto validate;
 }
 return input;
}

int findLowest(int accidents[])
{
 const int ARRAY_SIZE = 5;
 string lowestRegion;
 int accidents[ARRAY_SIZE];
 string regions[ARRAY_SIZE] = {"North", "South", "East", "West", "Central"};
 int lowest = 0;
 int counter = 0;
 while (counter < ARRAY_SIZE)
 {
  if (accidents[counter] < lowest)
  {
   lowest = accidents[counter];
   lowestRegion = regions[counter];
  }
  counter++;
 }
 cout<<"The "<<lowestRegion<<" region had the least accidents in the past year at " <<lowest<<" accidents."<<endl;
}
4

1 回答 1

18
        int findLowest(int accidents[])
    //                      ^^
        {
         const int ARRAY_SIZE = 5;
         string lowestRegion;
         int accidents[ARRAY_SIZE];
 //               ^^

accidents你有两个findLowest

于 2013-04-28T18:10:24.053 回答