C ++错误:ISO C ++禁止指针和整数之间的比较[-fpermissive]

时间:2014-07-22 04:01:23

标签: c++ shutdown dev-c++

我是初学者C ++程序员,对C ++知之甚少。我已经在IDE和编译器上创建了一个程序:Dev-C ++ 5.6.3。我遇到了这个错误:ISO C ++禁止指针和整数之间的比较[-fpermissive]。我不知道这意味着什么,但我会将整个代码放在这里:

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <conio.h>

using namespace std;
// This is the Cleaner and Updated version of the test program.

int main(int argc, char** argv) {

Introduction: //Introduction to The Program and Little Information About it.
cout << "________________________________________________________________________________" << endl;
cout << "                     Introduction                        " << endl;
cout << "________________________________________________________________________________" << endl;
cout << "Welcome to Ryan's C++ Program" << endl;
cout << "This Program is in Beta and is Glitchy" << endl;
cout << "Press Any Key to Continue..." << endl;
    getch();
        goto Lobby;

Lobby: //Main Place, Here you can go to multiple sections in the program that repersent diffrent functions.
system("CLS");
    int choice;
        cout << "________________________________________________________________________________" << endl;
        cout << "                      Lobby                       " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Please Enter the Corisponding Number to The Section You Want to Go to." << endl;
        cout << "1. Information (About Program)" << endl;
        cout << "2. Calculator" << endl;
        cout << "3. Games" << endl;
        cout << "4. Programs (To Open)" << endl;
        cout << "5. Shutdown Options (To Computer)" << endl;
        cout << "6. Help" << endl;
        cout << "7. About Me" << endl;
        cout << "8. Test" << endl;
        cout << "9. Exit Program" << endl;
        cout << "10. Update News" << endl;
        cout << "Input Number:";
        scanf ("%d", &choice);
            if (choice == 1) goto Information;
            if (choice == 2) goto Calculator;
            if (choice == 3) goto Games;
            if (choice == 4) goto Programs;
            if (choice == 5) goto Shutdown;

Information: //Information About The Program
system("CLS");
    cout << "________________________________________________________________________________" << endl;
    cout << "                    Information                       " << endl;
    cout << "________________________________________________________________________________" << endl;
    cout << "This is Information about The Program:" << endl;
    cout << "This Program is a C++ Console Program Using a Source Code Made by Ryan Park." << endl;
    cout << "This Program Was Made using the IDE and Compiler DEV-C++ Version 5.6.3." << endl;
    cout << "This Program is in Beta 1.0.0 and Might be Glitchy." << endl;
    cout << "To See the Contents of Every New Update, Go To: Update News Section." << endl;
    cout << "Press Any Key to Go Back to Lobby...." << endl;
        getch();
            system("CLS");
    cout << "Going Back to Lobby..." << endl;
    cout << "Press Any Key to Continue...." << endl;
        getch();
            goto Lobby;

Error: //Programs Emergency Error System.
system("CLS");
    cout << "Error Detected, Shutting Down Program..." << endl;
    cout << "Press Any Key to Continue....";
        getch();
            return 0;

Calculator: //Calculator With 4 Functions
int num1;
    system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                     Calculator                        " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Calculator!" << endl;
        cout << "To Begin, Please Select the Type of Operation You Want to Perform" << endl;
        cout << "1. Addition" << endl;
        cout << "2. Subtraction" << endl;
        cout << "3. Multiplication" << endl;
        cout << "4. Division" << endl;
        cout << "Input Number:";
            scanf ("%d", &num1);
    if (num1 == 1) goto Addition;
    if (num1 == 2) goto Subtraction;
    if (num1 == 3) goto Multiplication;
    if (num1 == 4) goto Division;
        else goto Error;

Addition: //Part of Calculator
int num2;
int num3;
int sum;
int input;
    system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                     Addition                        " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Addition!" << endl;
        cout << "1st Number:";
            scanf ("%d", &num2);
        cout << "2nd Number:";
            scanf ("%d", &num3);
                sum = num2 + num3;
        printf  ("\nThe Answer is: %d", sum);
        cout << "\nPress Any Key to Continue....";
            getch();
        system ("CLS");
        cout << "1. Go Back to Lobby" << endl;
        cout << "2. Go Back to Calculator" << endl;
        cout << "3. Make Another Addition Equation" << endl;
        cout << "Input Number:";
        scanf ("%d", &input);
        if (input == 1) goto Lobby;
        if (input == 2) goto Calculator;
        if (input == 3) goto Addition;
            else goto Error;

Subtraction: //Part of Calculator
int num4;
int num5;
int diffrence;
int input1;
    system("CLS");
            cout << "________________________________________________________________________________" << endl;
            cout << "                 Subtraction                            " << endl;
            cout << "________________________________________________________________________________" << endl;
            cout << "Welcome to Subtraction" << endl;
            cout << "1st Number:";
                scanf ("%d", &num4);
            cout <<  "2nd Number:";
                scanf ("%d", &num5);
                    diffrence = num4 - num5;
            printf ("\nThe Answer is: %d", diffrence);
            cout << "\nPress Any Key to Continue...." ;
                getch();
            system("CLS");
            cout << "1. Go Back to Lobby" << endl;
            cout << "2. Go Back to Calculator" << endl;
            cout << "3. Make Another Subtraction Operation" << endl;
            cout << "Input Number:";
            scanf ("%d", &input1);
                if (input1 == 1) goto Lobby;
                if (input1 == 2) goto Calculator;
                if (input1 == 3) goto Subtraction;  
                    else goto Error;

Multiplication: //Part of Calculator
int num6;
int num7;
int answer;
int choice2;
    system("CLS");
            cout << "________________________________________________________________________________" << endl;
            cout << "                 Multiplication                           " << endl;
            cout << "________________________________________________________________________________" << endl;
            cout << "Welcome to Multiplication" << endl;
            cout << "1st Number:";
                scanf ("%d", &num6);
            cout << "2nd Number:";
                scanf ("%d", &num7);
            answer = num6 * num7;
            printf ("\nThe Answer is: %d", answer);
            cout << "\nPress Any Key to Continue....";
                getch();
                    system("CLS");
            cout << "1. Go Back to Lobby" << endl;
            cout << "2. Go Back to Calculator" << endl;
            cout << "3. Make Another Multiplication Equation" << endl;
            cout << "Input Number:";
            scanf ("%d", choice2);
                if (choice2 == 1) goto Lobby;
                if (choice2 == 2) goto Calculator;
                if (choice2 == 3) goto Multiplication;
                    else goto Error;

Division: //Part of Calculator
int num8;
int num9;
int quotient;
int choice3;
    system("CLS");
            cout << "________________________________________________________________________________" << endl;
            cout << "                 Division                      " << endl;
            cout << "________________________________________________________________________________" << endl;
            cout << "Welcome to Division" << endl;
            cout << "1st Number:";
                scanf ("%d", &num8);
            cout << "2nd Number:";
                scanf ("%d", &num9);
                    quotient = num8 / num9 ;
            printf("\nThe Answer is: %d", quotient);
            cout << "\nPress Any Key to Continue....";
                getch();
                    system("CLS");
            cout << "1. Go Back to Lobby" << endl;
            cout << "2. Go Back to Calculator" << endl;
            cout << "3. Make Another Division Equation" << endl;
            cout << "Input Number:";
                scanf ("%d", choice3);
            if (choice3 == 1) goto Lobby;
            if (choice3 == 2) goto Calculator;
            if (choice3 == 3) goto Division;
                else goto Error;

Games: //Games Section. You Can play Games Here, Or Open Some. (NOT FINISHED/NOT STARTED)
system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                     Games                        " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Games" << endl;
        cout << "I Have not Started this Section Yet, But check here in the next update!" << endl;
        cout << "Current Version: BETA 1.0.0" << endl;
        cout << "Press Any Key to Continue...." << endl;
            getch();
            cout << "Going Back to Lobby..." << endl;
            cout << "Press Any Key to Continue...." << endl;
                getch();
                goto Lobby; 

Programs: //Programs, To Open Programs on Your Computer
system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                     Programs                        " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Programs" << endl;
        cout << "I have not Started this Section Yet, But check here in the next update!" << endl;
        cout << "Current Version: BETA 1.0.0" << endl;
        cout << "Press Any Key to Continue...." << endl;
            getch();
        cout << "Going Back to Lobby..." << endl;
        cout << "Press Any Key to Continue...." << endl;
            getch();
                goto Lobby; 

Shutdown: //Shutdown, To Shutdown, Restart and Log Off Computer.
int input3;
system("CLS");
    cout << "________________________________________________________________________________" << endl;
    cout << "                             Shutdown                       " << endl;
    cout << "________________________________________________________________________________" << endl;
    cout << "Welcome to the Shutdown Section" << endl;
    cout << "Which Operation Would you Like to Operate?" << endl;
    cout << "1. Shutdown" << endl;
    cout << "2. Restart" << endl;
    cout << "3. Log Off" << endl;
    cout << "4. Go Back to Lobby";
    cout << "Input Number:" << endl;
        scanf ("%d",&input3);
            if (input3 == 1) goto Shut;
            if (input3 == 2) goto Restart;
            if (input3 == 3) goto Log;
            if (input3 == 4) goto Lobby;
                else goto Error;

Shut:
char inputy;
system("CLS");
    cout << "________________________________________________________________________________" << endl;
    cout << "                             Shutdown                       " << endl;
    cout << "________________________________________________________________________________" << endl;
    cout << "Welcome to Shutdown" << endl;
    cout << "This Program Will Now Shutdown your Computer, Make Sure to Close and Save Your Files." << endl;
    cout << "Press Any Key to Continue...." << endl;
        getch();
    cout << "THIS WILL SHUTDOWN YOUR COMPUTER, ARE YOU SURE YOU WANT TO DO THIS?" << endl;
    cout << "(Y/N):";
        scanf ("%c", &inputy);
    if (inputy == "Y") goto Shut2;
    if (inputy == "y") goto Shut2;
    if (inputy == "n") goto Lobby;
    if (inputy == "N") goto Lobby;
        else goto Error;

Shut2:
cout << "Shutting Down Computer...." << endl;
cout << "Press Any Key to Continue...." << endl;
    getch();
        system("shutdown -s -t 10");

Restart:
int inputn;
system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                         Restart                           " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Restart" << endl;
        cout << "This Program Will Now Restart Your Computer, Make Sure to Close and Save Your Files." << endl; 
        cout << "Press Any Key to Continue...." << endl;
            getch();
        cout << "THIS PROGRAM WILL NOW RESTART YOUR COMPUTER, ARE YOU SURE YOU WANT TO DO THIS?" << endl;
        cout << "(Y/N):";
            scanf ("%c", &inputn);
            if (inputn == "Y") goto Re2;
            if (inputn == "y") goto Re2;
            if (inputn == "N") goto Lobby;
            if (inputn == "n") goto Lobby;
                else goto Error;


Re2:
cout << "Restarting Computer...." << endl;
cout << "Press Any Key to Continue...." << endl;
    getch();
        system("shutdown -r -t 10");                
 Log:
int inputl;
system("CLS");
        cout << "________________________________________________________________________________" << endl;
        cout << "                         Log Off                      " << endl;
        cout << "________________________________________________________________________________" << endl;
        cout << "Welcome to Log Off" << endl;
         cout << "This Program Will Now Log Off Your Computer, Make Sure to Close And   Save Your FIles." << endl;
        cout << "Press Any Key to Continue...." << endl;
            getch();
        cout << "THIS PROGRAM WILL NOW LOG OFF YOUR COMPUTER, ARE YOU SURE YOU WANT TO           DO THIS?" << endl;
        cout << "(Y/N):";
            scanf ("%c", &inputl);
            if (inputl == "Y") goto Log2;
            if (inputl == "y") goto Log2;
            if (inputl == "N") goto Lobby;
            if (inputl == "n") goto Lobby;
                else goto Error;

    Log2:
    cout << "Logging Off Computer...." << endl;
    cout << "Press Any Key to Continue...." << endl;
        getch();
            system("shutdown -l -t 10");

2 个答案:

答案 0 :(得分:6)

"Y""y""n""N"是C样式的字符串,它们是以空字符结尾的字符数组。在尝试比较它们时,它们会退化为指向const char的指针。另一方面,inputy被声明为int。这是指针和整数错误之间比较的起源。

要解决此问题,请将inputy与字符进行比较,而不是字符串:'Y''y''n''N'(请注意单引号,而不是双引号。)

答案 1 :(得分:2)

你还有另外一个问题。您已宣布int inputy;,但您正在尝试通过scanf("%c", &inputy);阅读字符。格式字符串%c&inputy的数据类型不匹配。如果要读取字符,则应使用输入变量的正确类型:

char inputy;

scanf("%c", &inputy);