试图让我的程序将int值从0更改为1

时间:2017-02-25 23:18:44

标签: c++ pointers

#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 ++完全陌生,我只是学习了If和If - else。但我认为我知道足以创建一种类型的数据库菜单程序。我用谷歌搜索了如何更改int值,我发现了几个帖子,我试图在这里处理指针,但我显然没有这方面的经验,我不知道该怎么做。请帮我解决这个问题,我已经做了好几个小时。

1 个答案:

答案 0 :(得分:-1)

你可以使用bool摆脱你的整个问题,只显示一两个。