如何调用函数和未使用的表达式错误
how to call functions and unused expression error
我得到一个错误说:使用未声明的标识符'再次'。我正试图从主再次无效,并得到答案后回来。请向我解释为什么它也不起作用。谢谢。
下面是我的完整代码: #include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
{
string answer;
cout << "Would you like to enter another set of data? Y or N?" << endl;
cin << answer;
string yes = "Yes";
string no = "No";
if(a == yes)
{
main();
}
}
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 11 - Vectors" << endl;
cout << "November 12, 2016" <<endl;
cout << endl;
cout << endl;
int size;
cout << " How many numbers would you like the vector to hold? " << endl;
cin >> size;
vector<int> numbers;
int bnumbers;
for (int count = 0; count < size; count++)
{
cout << "Enter a number: " << endl;
cin >> bnumbers;
numbers.push_back(bnumbers); // Adds an element to numbers
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int bcount = 0; bcount < size; bcount++)
{
cout << numbers[bcount] << " ";
}
cout << endl;
//display the numbers stored reversed
cout << "Here are the numbers in reverse order: " << endl;
reverse(numbers.begin(), numbers.end());
for(int rcount = 0; rcount < size; rcount++)
{
cout << numbers[rcount] << " ";
}
cout << endl;
again();
return 0;
}
void again()
}
你需要在调用它之前"再次"声明你的函数:
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
void again();
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 11 - Vectors" << endl;
cout << "November 12, 2016" <<endl;
cout << endl;
cout << endl;
int size;
cout << " How many numbers would you like the vector to hold? " << endl;
cin >> size;
vector<int> numbers;
int bnumbers;
for (int count = 0; count < size; count++)
{
cout << "Enter a number: " << endl;
cin >> bnumbers;
numbers.push_back(bnumbers); // Adds an element to numbers
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int bcount = 0; bcount < size; bcount++)
{
cout << numbers[bcount] << " ";
}
cout << endl;
//display the numbers stored reversed
cout << "Here are the numbers in reverse order: " << endl;
reverse(numbers.begin(), numbers.end());
for(int rcount = 0; rcount < size; rcount++)
{
cout << numbers[rcount] << " ";
}
cout << endl;
again();
return 0;
}
void again()
{
string answer;
cout << "Would you like to enter another set of data? Y or N?" << endl;
cin >> answer;
string yes = "Yes";
string no = "No";
if(answer == yes)
{
main();
}
}
然而,对于你想要做的事情使用递归并多次调用main函数(根据定义,它是程序的主入口)是一件奇怪的事情。在我看来,你应该在你的主函数中调用另一个名为askInformation的函数,它使用一个带有测试用例的循环来知道用户是否想要添加信息。
相关文章:
- 普通环路未使用gcc 4.8.5自动矢量化
- 在更改for循环的第三部分后,未使用for循环结果
- 使用typeid警告未使用的变量
- C++删除未使用的类属性会导致 std::logic_error
- 警告 C4552:">>":未使用表达式的结果
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 为什么我会收到警告,指出函数已使用但未定义,以及已定义但未使用?
- 如果我想链接静态库并删除未使用的符号.txt我应该如何处理 Cmakelist
- 可视化C++载体:未使用的容量
- GCC 中 __attribute__((未使用)) 和 __attribute((未使用)) 之间的区别
- 循环访问还包含未使用元素的字符串数组
- Q维德格特关闭事件(..)未使用 QProcess::terminate() 调用
- C++如何使用表达式获取用户输入?
- Visual Studio "fatal error LNK1104: cannot open file"未使用或包含的库
- G++ 编译器是否在未使用返回值的情况下将 constexpr 函数视为常规函数?
- 删除未使用新表达式构建的对象实际上可以吗?
- 表达式结果未使用,图像生成
- 警告:表达式结果未使用
- 如何调用函数和未使用的表达式错误
- 未使用常量表达式初始化ID_BUTTON