Program.exe has stopped working

-1

I'm with this code, a little ugly. I want to know why I get it

  

Program.exe has stopped working

I've been looking for the error for a long time, thanks in advance.

            #include <iostream>
            #include <stdlib.h>
            #include <windows.h>
            using namespace std;

            struct Medico{
                string nombre;
                string especialidad;
                string servicios[2];
            };
            struct Paciente{
                string nombre;
                int edad;
                int seguro;
                int recaudado;
            };


            int acseguro(int,Paciente[],int);
            void recaudos(int,int,int);
            //void  moc(string[],int,string[], int);
            int main()
            {
                SetConsoleTitle("El Paciente Feliz");
                int ocurrencias[7][4];
                int tota=0,totb=0,totc=0,totd=0,totaa=0,totbb=0,totcc=0,totdd=0,totaaa=0,totbbb=0,totccc=0,totddd=0,totaaaa=0,totbbbb=0,totcccc=0,totdddd=0,totaaaaa=0,totbbbbb=0,totccccc=0,totddddd=0,totaaaaaa=0,totbbbbbb=0,totcccccc=0,totdddddd=0,totaaaaaaa=0,totbbbbbbb=0,totccccccc=0,totddddddd=0;
                int dinero=0,ingresado=0,cantidadserv,cantidadespe,monto=0,posesp=0,posser=0,costo=0,paga,recaucentro=0,contpacientes=0,totpacientes=0;;
                string espe[5],serv[5];
                Paciente pacien[10];
                float seguro[4]={1,0.1,0.5,0.10};
                int ocurrenciass[7][4],e=7,s=4,precios[e][s]={{45000,500000,15000,25000},{25000,250000,15000,15000},{45000,300000,40000,0},{25000,300000,20000,0},{30000,500000,25000,0},{10000,150000,10000,10000},{15000,300000,15000,0}};
                string especialidades[7]={"cardiologia","traumatologia","oncologia","otorrinolaringologia","neurologia","optometria","ginecologia"};
                string servicios[4]={"consulta","cirugia","examen","terapia"};

                { //matriz de precios
                cout<<"\n"<<"\n";
                cout<<"\t" <<"\t" <<"\t"<<"\t"<<"Bienvenido al Centro Medico El Paciente Feliz."<<"\n";
                cout<<"                 __________________________________________________________________________________________________"<<"\n"<<"\n";
                cout<<"\t"<<"\t"<<"\t"<<"Consulta"<<"\t"<<"\t"<<"Cirug"<<char(161)<<"a"<<"\t"<<"\t"<<"\t"<<"Examen"<<"\t"<<"\t"<<"\t"<<"Terapia"<<"\n";
                cout<<"\n"<<"Cardiolog"<<char(161)<<"a:"<<"\t"<<"\t"<<"$45.000"<<"\t"<<"\t"<<"\t"<<"$500.000"<<"\t"<<"\t"<<"\t"<<"$15.000"<<"\t"<<"\t"<<"\t"<<"$25.000";
                cout<<"\n"<<"Traumatolog"<<char(161)<<"a:"<<"\t"<<"\t"<<"$25.000"<<"\t"<<"\t"<<"\t"<<"$250.000"<<"\t"<<"\t"<<"\t"<<"$15.000"<<"\t"<<"\t"<<"\t"<<"$15.000";
                cout<<"\n"<<"Oncolog"<<char(161)<<"a:"<<"\t"<<"\t"<<"$45.000"<<"\t"<<"\t"<<"\t"<<"$300.000"<<"\t"<<"\t"<<"\t"<<"$40.000"<<"\t"<<"\t"<<"\t"<<"$0";
                cout<<"\n"<<"Otorrinolaringolog"<<char(161)<<"a:"<<"\t"<<"$25.000"<<"\t"<<"\t"<<"\t"<<"$300.000"<<"\t"<<"\t"<<"\t"<<"$20.000"<<"\t"<<"\t"<<"\t"<<"$0";
                cout<<"\n"<<"Nerolog"<<char(161)<<"a:"<<"\t"<<"\t"<<"$30.000"<<"\t"<<"\t"<<"\t"<<"$500.000"<<"\t"<<"\t"<<"\t"<<"$25.000"<<"\t"<<"\t"<<"\t"<<"$0";
                cout<<"\n"<<"Optometr"<<char(161)<<"a:"<<"\t"<<"\t"<<"$10.000"<<"\t"<<"\t"<<"\t"<<"$150.000"<<"\t"<<"\t"<<"\t"<<"$10.000"<<"\t"<<"\t"<<"\t"<<"$10.000";
                cout<<"\n"<<"Ginecolog"<<char(161)<<"a:"<<"\t"<<"\t"<<"$15.000"<<"\t"<<"\t"<<"\t"<<"$300.000"<<"\t"<<"\t"<<"\t"<<"$15.000"<<"\t"<<"\t"<<"\t"<<"$0"<<endl;
                cout<<"                 __________________________________________________________________________________________________";
                cout<<"\n \n";
                cout<<"SEGUROS";
                cout<<"\n";
                cout<<"\n"<<"Tipo 1: 0%"<<"\t"<<"Tipo 2: 10%"<<"\t"<<"Tipo 3: 50%"<<"\t"<<"Tipo 4: 100%"<<"\n \n";
                cout<<endl;
                system("PAUSE");
                system("CLS");

                cout<<"          _____________________________________________________________________________________________________"<<endl;
                cout<<"         |                                                                                                     |"<<endl;
                cout<<"         |En el centro medico el 'El Paciente Feliz' trabajamos por ti, por favor llena los siguientes datos :)|"<<endl;
                cout<<"         |_____________________________________________________________________________________________________|"<<endl;

                cout<<"\n";
                }

                for(int w=0;w<10;w++){
                    cout<<"Bienvenido, ingresa tu nombre: ";
                    cin>>pacien[w].nombre;
                    cout<<"Ingresa tu edad, "<<pacien[w].nombre<<": "; //acá leo el valor y saco precio

                    cin>>pacien[w].edad;
                    cout<<"Ingresa tu tipo de seguro: ";
                    cin>>pacien[w].seguro;
                    cout<<"\n"<<char(168)<<"En cu"<<char(160)<<"ntas especialidades necesitas ser atentido?: ";
                    cin>>cantidadespe;

                        for(int i=0;i<cantidadespe;i++){
                            cout<<char(168)<<"En qu"<<char(130)<<" especialidad deseas ser atentido?: ";
                            cin>>espe[i];
                            for(int j=0;j<7;j++){
                                    if(especialidades[j]==espe[i]){
                                        posesp=j;
                                    }
                            }


                            cout<<char(168)<<"Cu"<<char(160)<<"ntos servicios necesitas de "<<espe[i]<<"?: ";
                            cin>>cantidadserv;

                                for(int k=0;k<cantidadserv;k++){
                                    cout<<char(168)<<"Qu"<<char(130)<<" servicio deseas para "<<espe[i]<<"?: ";
                                    cin>>serv[k];
                                        for(int p=0;p<4;p++){
                                                if(servicios[p]==serv[k]){
                                                    posser=p;
                                                }
                                    }
                                    costo=costo+precios[posesp][posser];
                                    paga=acseguro(costo,pacien,w);


                        {//no abrir, no mover

                    if((espe[i]=="cardiologia")&&(serv[k]=="consulta")){
                        tota++;
                        }
                    if((espe[i]=="cardiologia")&&(serv[k]=="cirugia")){
                        totb++;
                        }
                    if((espe[i]=="cardiologia")&&(serv[k]=="examen")){
                        totc++;
                        }
                    if((espe[i]=="cardiologia")&&(serv[k]=="terapia")){
                        totd++;
                        }
                    if((espe[i]=="traumatologia")&&(serv[k]=="consulta")){
                        totaa++;
                        }
                    if((espe[i]=="trumatologia")&&(serv[k]=="cirugia")){
                        totbb++;
                        }
                    if((espe[i]=="traumatologia")&&(serv[k]=="examen")){
                        totcc++;
                        }
                    if((espe[i]=="traumatologia")&&(serv[k]=="terapia")){
                        totdd++;
                        }
                    if((espe[i]=="oncologia")&&(serv[k]=="consulta")){
                        totaaa++;
                        }
                    if((espe[i]=="oncologia")&&(serv[k]=="cirugia")){
                        totbbb++;
                        }
                    if((espe[i]=="oncologia")&&(serv[k]=="examen")){
                        totccc++;
                        }
                    if((espe[i]=="oncologia")&&(serv[k]=="terapia")){
                        totddd++;
                        }
                    if((espe[i]=="otorrinolaringologia")&&(serv[k]=="consulta")){
                        totaaaa++;
                        }
                    if((espe[i]=="otorrinolaringologia")&&(serv[k]=="cirugia")){
                        totbbbb++;
                        }
                    if((espe[i]=="otorrinolaringologia")&&(serv[k]=="examen")){
                        totcccc++;
                        }
                    if((espe[i]=="otorrinolaringologia")&&(serv[k]=="terapia")){
                        totdddd++;
                        }
                    if((espe[i]=="neurologia")&&(serv[k]=="consulta")){
                        totaaaaa++;
                        }
                    if((espe[i]=="neurologia")&&(serv[k]=="cirugia")){
                        totbbbbb++;
                        }
                    if((espe[i]=="neurologia")&&(serv[k]=="examen")){
                        totccccc++;
                        }
                    if((espe[i]=="neurologia")&&(serv[k]=="terapia")){
                        totddddd++;
                        }
                    if((espe[i]=="optometria")&&(serv[k]=="consulta")){
                        totaaaaaa++;
                        }
                    if((espe[i]=="optometria")&&(serv[k]=="cirugia")){
                        totbbbbbb++;
                        }
                    if((espe[i]=="optometria")&&(serv[k]=="examen")){
                        totcccccc++;
                        }
                    if((espe[i]=="optometria")&&(serv[k]=="terapia")){
                        totdddddd++;
                        }
                    if((espe[i]=="ginecologia")&&(serv[k]=="consulta")){
                        totaaaaaaa++;
                        }
                    if((espe[i]=="ginecologia")&&(serv[k]=="cirugia")){
                        totbbbbbbb++;
                        }
                    if((espe[i]=="ginecologia")&&(serv[k]=="examen")){
                        totccccccc++;
                        }
                    if((espe[i]=="ginecologia")&&(serv[k]=="terapia")){
                        totddddddd++;
                        }
                    }
                        {//no abrir, no mover




                    while(1==1){
                            ocurrencias[0][0]=tota;
                            ocurrencias[0][1]=totb;
                            ocurrencias[0][2]=totc;
                            ocurrencias[0][3]=totd;
                            ocurrencias[1][0]=totaa;
                            ocurrencias[1][1]=totbb;
                            ocurrencias[1][2]=totcc;
                            ocurrencias[1][3]=totdd;
                            ocurrencias[2][0]=totaa;
                            ocurrencias[2][1]=totbb;
                            ocurrencias[2][2]=totcc;
                            ocurrencias[2][3]=totdd;
                            ocurrencias[3][0]=totaaa;
                            ocurrencias[3][1]=totbbb;
                            ocurrencias[3][2]=totccc;
                            ocurrencias[3][3]=totddd;
                            ocurrencias[4][0]=totaaaa;
                            ocurrencias[4][1]=totbbbb;
                            ocurrencias[4][2]=totcccc;
                            ocurrencias[4][3]=totdddd;
                            ocurrencias[5][0]=totaaaaa;
                            ocurrencias[5][1]=totbbbbb;
                            ocurrencias[5][2]=totccccc;
                            ocurrencias[5][3]=totddddd;
                            ocurrencias[6][0]=totaaaaaa;
                            ocurrencias[6][1]=totbbbbbb;
                            ocurrencias[6][2]=totcccccc;
                            ocurrencias[6][3]=totdddddd;
                            ocurrencias[7][0]=totaaaaaaa;
                            ocurrencias[7][1]=totbbbbbbb;
                            ocurrencias[7][2]=totccccccc;
                            ocurrencias[7][3]=totddddddd;

                            break;
                    }
            }


                                }
                        }
                        recaucentro=recaucentro+paga;
                        recaudos(paga,recaucentro,costo);
                        costo=0;
                        contpacientes++;


                        system("PAUSE");

               {
                system("CLS");
                cout<<"          _____________________________________________________________________________________________________"<<endl;
                cout<<"         |                                                                                                     |"<<endl;
                cout<<"         |En el centro medico el 'El Paciente Feliz' trabajamos por ti, por favor llena los siguientes datos :)|"<<endl;
                cout<<"         |_____________________________________________________________________________________________________|"<<endl;

                cout<<"\n";
               }
            }
                for(int m=0;m<7;m++){
                        for(int n=0;n<4;n++){
                            cout<<ocurrencias[m][n]<<"\t";
                        }
                        cout<<"\n";
                    }

            }


            int acseguro(int costo,Paciente pacien[10],int w){

                int deuda=0;
                switch(pacien[w].seguro){
                case 1:   deuda=costo;
                            break;
                case 2:   deuda=costo-(costo*0.1)+1;
                            break;
                case 3:   deuda=costo-(costo*0.5);
                            break;
                case 4:   deuda=0;
                            break;
                default:    break;
                }
                return deuda;
            }

            void recaudos(int paga, int recaucentro, int costo){
                    cout<<"\n"<<"La deuda es de "<<costo<<", aplicando descuento de seguro queda en "<<paga<<endl;
                    cout<<"El recaudado por el Centro Medico es de "<<recaucentro<<endl;
            }

    
asked by Diego Patiño 06.11.2017 в 05:58
source

1 answer

1
  

I'm with this code, a little ugly ...

It is easier to find errors (or even avoid committing them) in clean and readable codes than in the framework of a scary movie.

On the other hand, I do not finish understanding the reasons that lead to the code that you present being able to show the message you indicate:

error 1

main.cpp:24: error: C2664: 'BOOL SetConsoleTitleW(LPCWSTR)': cannot convert argument 1 from 'const char [18]' to 'LPCWSTR'

Specifically here:

SetConsoleTitle("El Paciente Feliz");

Why? The function is Windows and, the same, requires a parameter of type LPCWSTR (a alias of const wchar_t* ) and you are passing it a char* ... which is not the same. You have to add the prefix L to the string:

SetConsoleTitle(L"El Paciente Feliz");
//              ^

Error 2

main.cpp:31: error: C2131: expression did not evaluate to a constant

Here:

precios[e][s]=

Why?

e and s are variables and precios a matrix with dimensions e and s . This is known as VLA (Variable Length Array) and is a feature not covered in the C ++ standard ... so you have many ballots so that your code does not work according to what compilers.

If the values of e and s are fixed, consider using constants:

const int e = 7;
const int s = 4;
int precios[e][s] = { /* ... */ };

and, of course, if you already have some variables (or constants) to control these dimensions ... use them :

// mal
for(int m=0;m<7;m++){
  for(int n=0;n<4;n++){
    cout<<ocurrencias[m][n]<<"\t";
  }
  cout<<"\n";
}

// bien
for(int m=0;m<e;m++){
  for(int n=0;n<s;n++){
    cout<<ocurrencias[m][n]<<'\t';
  }
  cout<<'\n';
}

Additionally, you must include the #include <string> header in order to correctly use type std::string .

And do not forget to review the string of warnings . If the compiler is giving you so many warnings it is for something.

After all this the program compiles, runs and does not crack ... I've been tempted to vote to close this question by typo, but I think it's going to be more instructive to leave these steps in response so you can see and learn from your mistakes.

    
answered by 06.11.2017 в 07:59