函数参数中未声明和未定义的标识符
Undeclared and undefined identifier's in the parameter of a function
#include <stdio.h>
#include <iostream>
using namespace std;
void instructions();
int menu();
void drawt(int& s, char& c);
int main()
{
int choice;
instructions();
choice = menu();
if (choice != 1 && choice != 2)
{
cout << "You requested to quit. Bye! n";
return 0;
}
if (choice = 1) {
drawt(s, c);
}
//draw the shape the user requested
//draw_shape(choice);
system("pause");
return 0;
}
void instructions() {
cout << "This program will create a triangle or diamond of your choice in
size!n";
cout << "The number you enter will either be the size of the bottom of the
triangle or the size of the middle of the diamond!n";
}
int menu() {
int c;
cout << "Please choose between drawing a triangle, diamond or exiting the
program!n";
cout << "Enter 1 for a triangle,2 for a diamond and 3 to exit!n";
cin >> c;
return c;
}
void drawt(int& s, char& c){
cout << "enter base size of trianglen";
cin >> s;
cout << "Now enter the character you wish the triangle to be made of!n";
cin >> c;
int length = 1;
for (int i= 0; i < 5; i++) {
for (int j = 0; j < s; j++) {
cout << c;
}
cout << endl;
length++;
if (length = s) {
break;
}
}
}
它说s和c都是未定义的,没有确定的,我不知道为什么它不起作用。我只是学会了功能,我不确定我是正确地称其为正确还是正确地使用了标题或确切的内容做错了。我抬头看了很多教程等。该程序应该画出一个三角形或钻石的人,然后以任何人的选择,然后从他们选择的特征中绘制出来。它还没有完成,但是我现在如此挂断。谢谢!
当您从main()
调用此功能时:
drawt(s, c);
您将2个变量S和C发送到该函数。但是这些变量在main()
中还不存在 - 这是这里的汇编问题。您需要首先在main()
中声明它们:
int s;
char c;
应该解决您的基本问题。
您应该尝试更多的功能练习。您在定义drawt()
的方式上存在一些问题(并非关键) - 它使用的是可以在本地定义的参数,即使main()
从未使用过它们,也可以将其作为参考接收。这些是您应该学习的重要事情,但是它们不会像现在这样打破您的程序。
另外,您应该立即开始始终如一 - 非常重要:)
相关文章:
- Visual Studio C++ PlaySound 标识符未定义
- 删除动态数组时未定义标识符
- 未定义的标识符/未声明
- 标识符Class_name未定义C++ oop
- 标识符"hWnd"未定义
- 为什么更改包含 psapi.h 的顺序会产生编译错误?(标识符 BOOL 未定义)
- Visual Studio 2019 概念标识符未定义
- 标识符"DDRB"未定义 - VS code / Visual Studio
- 在头文件中使用opencv类型来实现未定义的标识符
- 标识符"in"未定义
- 智能感知:标识符"node"未定义
- 标识符"__readgsqword"未定义 - Visual Studio 2017
- 标识符"V 未定义
- 标识符"thread"未定义
- 标识符uint8_t未定义 - Visual Studio 2017
- 未定义的标识符 - 缺少哪些头文件?- DX12.
- 调用函数时未定义标识符"function_name"
- Wininet未定义标识符
- 简单代码问题-未定义标识符
- 试图编写函数的未定义标识符