试图使我的程序将INT值从0更改为1
Trying to make my program change an int value from 0 to 1
#include <iostream>
using namespace std;
int profileClearanceLevel = 0;
void clearanceLevel (int **a) {
*a = &profileClearanceLevel;
}
int main() {
cout << "Greetings and welcome to the Aperture Science Enrichment Center Employee Database." << endl;
string enterToContinue = "Press enter to continue.";
cout << enterToContinue << endl;
cin.get();
cout << "Please input ID: " << flush;
int identificationNumber;
cin >> identificationNumber;
while (identificationNumber < 1) {
cout << "Specified profile not found. Please try again." << endl;
cout << enterToContinue << endl;
cin.get();
cin.get();
cout << "Please input ID: " << flush;
cin >> identificationNumber;
}
while (identificationNumber > 1) {
cout << "Specified profile not found. Please try again." << endl;
cout << enterToContinue << endl;
cin.get();
cin.get();
cout << "Please input ID: " << flush;
cin >> identificationNumber;
}
clearanceLevel (&profileClearanceLevel);
int *profileClearanceLevel = 0;
if (identificationNumber == 1) {
cout << "Please input your password: " << flush;
int profilePassword;
cin >> profilePassword;
while (profilePassword != 2356) {
cout << "Incorrect password. Please try again." << endl;
cout << enterToContinue << endl;
cin.get();
cin.get();
cout << "Please input your password: " << flush;
cin >> profilePassword;
}
if (profilePassword == 2356) {
int employeeNumber = 1;
int *profileClearanceLevel = 1;
cout << "Welcome, Employee #" << employeeNumber << endl;
cout << "Clearance level: " << profileClearanceLevel << endl;
cout << enterToContinue << endl;
cin.get();
cin.get();
}
}
if (*profileClearanceLevel == 1) {
cout << "it worked" << endl;
return 0;
}
}
这是我遇到的错误:
00:12:58 **** Incremental Build of configuration Debug for project Menu ****
make all
Building file: ../src/Menu.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Menu.d" -MT"src/Menu.o" -o "src/Menu.o" "../src/Menu.cpp"
../src/Menu.cpp: In function 'int main()':
../src/Menu.cpp:35:44: error: cannot convert 'int*' to 'int**' for argument '1' to 'void clearanceLevel(int**)'
clearanceLevel (&profileClearanceLevel);
^
../src/Menu.cpp:51:37: error: invalid conversion from 'int' to 'int*' [-fpermissive]
int *profileClearanceLevel = 1;
^
make: *** [src/Menu.o] Error 1
00:12:59 Build Finished (took 723ms)
我是C 的新手,我只能学习是否以及是否 - 其他。但是我认为我足够了解,可以创建一种类型的数据库菜单程序。我搜索了如何更改INT值的方式,然后遇到了几篇文章,并试图在这里处理指针,但是我显然没有经验,我不知道该怎么办。请帮助我解决此问题,我已经这样做了几个小时。
您可以使用布尔来摆脱整个问题,只需显示一个或两个。
相关文章:
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 如何在不强制转换每个参数的情况下删除初始值设定项列表中从 int 到 char 的缩小转换?
- 在排序数组中搜索最接近的 int 值 <= 从右起给定值
- 如何修复数组赋值从 ascii 值到 int
- isspace 函数的性能警告,从 int 转换为布尔值
- 试图使我的程序将INT值从0更改为1
- C - 使用BitMask从INT获取值
- G 警告:从INT转换为UINT16_T可能会改变其值
- 如何将数组的一部分从 int 转换为浮点数并将值设置为另外两个数组
- 从 int 转换为 std::array<unsigned char, 1ul>::value_type 可能会改变其值
- 从 int 类型的右值初始化 &分数类型的非常量引用无效?
- 将多重映射值从 int 转换为字符串
- 从文本文件中提取特定值(char & int)并插入到多个变量中C++
- gcc 奇怪的转换警告(<B>从"int"转换为"A::count_type {aka short unsigned int}"可能会改变其值)
- 警告:从'int'转换为'unsigned char'可能会更改其值
- 从兼容类型int中赋值给int
- 为什么按位否定运算符"~"转换为 int?(从"int"转换为"无符号字符"可能会改变其值)
- 正在从二进制文件中读取双值和int值
- 从"int"到非标量类型赋值运算符的转换 - 对象到 int
- 如何解决此警告:从'int'转换为'unsigned char'可能会更改其值