简体   繁体   中英

C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]

I am a beginner C++ Programmer With Very little knowledge about C++. I Have Been Creating a Program on The IDE and Compiler: Dev-C++ 5.6.3. I have run into this error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]. I don't know what it means but I will put the whole code here:

#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");

"Y" , "y" , "n" , and "N" are C-style strings, which are null-terminated character arrays. When attempting to compare them, they degenerate to pointers to const char . On the other hand, inputy is declared as int . This is the origin of your comparison between pointer and integer errors.

To fix the issue, compare inputy against characters instead of strings: 'Y' , 'y' , 'n' , and 'N' (note the single quotes, rather than double quotes).

You have another problem. You've declared int inputy; but you are trying to read a character by doing scanf("%c", &inputy); . The format string %c does not match the data type of &inputy . If you want to read a character you should use the correct type for the input variable:

char inputy;

scanf("%c", &inputy);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM