宣布“国际事故[5]"掩盖了参数错误 [英] Declaration of 'int accidents[5]' shadows a parameter error

查看:57
本文介绍了宣布“国际事故[5]"掩盖了参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to C++ and can't find any way around this error. As far as I know I'm not overloading any variables to create a conflict with naming(which was the closest thing to a cause i could find online). Any help would be much appreciated.

#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;
}

推荐答案

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

您的findLowest

这篇关于宣布“国际事故[5]"掩盖了参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆