试图使我的程序将INT值从0更改为1

Trying to make my program change an int value from 0 to 1

本文关键字:值从 INT 我的 程序      更新时间:2023-10-16
#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值的方式,然后遇到了几篇文章,并试图在这里处理指针,但是我显然没有经验,我不知道该怎么办。请帮助我解决此问题,我已经这样做了几个小时。

您可以使用布尔来摆脱整个问题,只需显示一个或两个。