Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

([Error] ISO C++ forbids comparison between pointer and integer)

I am new to C++ and to programming in general. I am trying to make this small code but when I want to use the if function I get this error.

I have no idea what it could be. I tried several conventions and none of them work.
I was hoping someone could give me advice on how to write this line of code better.
here is the thing

#include <iostream>
#define EXIT_SUCCESS 0
using namespace std;

int main()
{
    //variables
    char cod_ref[6];
    char des_prod[60];
    char disp;
    int size;
    int cost;
    int price;
    int num;
    //impresiones y asignaciĂłn de variables
    cout<<"Digite el codigo de referencia del producto (5 digitos)" << endl;
    cin.getline(cod_ref, 6);
    cout<<"Digite la descripciĂłn del producto"<<endl;
    cin.getline(des_prod, 60);
    cout<<"Digite la talla del producto"<<endl;
    cin>>size;
    cout<<"Cantidad de productos"<<endl;
    cin>>num;
    cout<<"ÂżDisponible para la venta? S/N"<<endl;
    cin>>disp;
    cout<<"Digite el costo por unidad"<<endl;
    cin>>cost;
    cout<<"Digite el precio de venta por unidad"<<endl;
    cin>>price;

    //limpieza de pantalla
    system("cls");
    //impresiĂłn final
    cout<<"REFERENCIA: "<< cod_ref <<endl;
    cout<<"DESCRIPCIÓN: "<< des_prod  <<endl;
    cout<<"DISPONIBILIDAD: ";
    if( disp == "s"||"S" ){
        cout<<"Disponible";
    }else{
        cout<<"No Disponible";
    }
    cout<<"COSTO UNIDAD: "<< cost <<endl;
    cout<<"COSTO TOTAL: "<< cost * num <<endl;
    cout<<"PRECIO UNIDAD: "<< price <<endl;
    cout<<"PRECIO POR "<< num <<" UNIDADES: "<< price * num <<endl;
    cout<<"GANANCIA POR UNIDAD: "<< price - cost <<endl; 
    cout<<"GANANCIA TOTAL: " << (price * num) - (cost * num) <<endl;
    //cout<<"PORCENTAGE DE GANANCIA: "<<
    
    system("pause");
    return EXIT_SUCCESS;
}


here is where i get the error
if( disp == "s"||"S" ){

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use single quotes for char character comparisons, double quotes implies a string which is technically a char * type.

ie.

if (disp == 's' || disp == 'S')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading