C++ 收到错误,指出函数未在此范围内声明
C++ Receiving error that the function was not declared in this scope
这是我为我大学的作业写的图片。我已经编写了从用户那里获取 10 个整数的所有代码,并要求用户按 1 按列表中的升序显示奇数整数,或按 2 按列表中的升序显示偶数。
好吧,我已经在程序中的main()函数之前声明并定义了气泡排序函数,并在main()中使用该函数按升序对偶数和奇数进行排序。但是,即使我在顶部声明了函数,我仍然收到错误,即该函数未在此范围内声明。我尝试了所有我能做的事情。请帮我做什么?下面是我的代码
#include <iostream>
#include <conio.h>
using namespace std;
void BuubleSort_Function(int [], int);
void BuubleSort_Function(int arr[], int arrSize)
{
int extraMem;
for(int i = 0; i < arrSize; i++)
{
for(int arrIndex = 0; arrIndex < arrSize - 1; arrIndex++)
{
if(arr[arrIndex] > arr[arrIndex+1])
{
extraMem = arr[arrIndex];
arr[arrIndex] = arr[arrIndex+1];
arr[arrIndex+1] = extraMem;
}
}
}
}
main()
{
int num[10], i, even[10], odd[10], inputOpt, totalEvens = 0, totalOdds = 0;
system("cls");
cout << "Please enter 10 integers: " << endl;
for(i = 0; i < 10; i++)
{
cin >> num[i];
}
cout << endl << endl << endl << "1. Show odd numbers in ascending order and their total numbers" << endl;
cout << "2. Show even numbers in ascending order and their total numbers" << endl;
do
{
cout << endl << "Enter 1 for the first option or 2 for the second option: ";
cin >> inputOpt;
if(inputOpt != 1 && inputOpt != 2)
{
cout << "Wrong Input! Please enter the correct input value";
}
}
while(inputOpt != 1 && inputOpt != 2);
if(inputOpt == 1)
{
for(i = 0; i < 10; i++)
{
if(num[i] % 2 == 1)
{
odd[totalOdds] = num[i];
totalOdds++;
}
}
BubbleSort_Function(odd,totalOdds);
cout << endl << "The total numbers of Odds Integers are " << totalOdds;
cout << endl << "The Integers arranged in Ascending Order:" << endl;
for(i = 0; i < totalOdds; i++)
{
cout << odd[i] << "t";
}
}
if(inputOpt == 2)
{
for(i = 0; i < 10; i++)
{
if(num[i] % 2 == 0)
{
even[totalEvens] = num[i];
totalEvens++;
}
}
BubbleSort_Function(even,totalEvens);
cout << endl << "The total numbers of Odds Integers are " << totalEvens;
cout << endl << "The Integers arranged in Ascending Order:" << endl;
for(i = 0; i < totalEvens; i++)
{
cout << even[i] << "t";
}
}
}
一个简单的错别字:函数被声明并实现为BuubleSort_Function
。
您尝试使用BubbleSort_Function
调用它。
编译器错误消息非常有用。一定要学会解释它们。
(最后,标准C++要求您将main()
标记为返回int
- 如果缺少隐式return 0
,C++编译器会将隐式插入main
。一些编译器 - 特别是嵌入式系统的编译器 - 放弃了这个要求,但这偏离了标准。
定义 -BuubleSort_Function
呼叫者 -BubbleSort_Function
将第5 行和第 7 行与第 64 行进行比较,您会发现问题所在。只是一个简单的错别字。
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明