“可以转换”;“bool”;变成;常量字符“;错误和错位else错误c++; 我正在学习C++。我遇到了一个无法将“bool”转换为“const char”的错误,这是我能运行的“first strcmp”中最烦人的错误。在那之后,我得到了错误。我试图修复它,但如果我这样做了,就会显示出很多错误。我被困在这里,不知道该怎么办 #include<stdio.h> #include<conio.h> #include<iostream.h> #include<string.h> main() { char kode[6][12],merk[15]; int j,a,mobil[6],banyak[6]; long harga[6]; cout<<"\t\t\t|----------------------------|"<<endl; cout<<"\t\t\t|***Rental mobil sederhana***|"<<endl; cout<<"\t\t\t| ***Jl. Tebet raya no.15*** | "<<endl; cout<<"\t\t\t|----------------------------|"<<endl; cout<<" "<<endl; cout<<"merk mobil yang tersedia : 1. DAIHATSU Kode : DA"<<endl; cout<<" 2. TOYOTA Kode : TO"<<endl; cout<<" 3. HONDA Kode : HO"<<endl; cout<<"Banyak mobil yang ingin disewa : "; cin>>j; banyak[j]=0; if(j<=0) { for(a=1;a<=j; a++) { cout<<"Mobil ke :"<<a<<endl; cout<<"kode merk :"; cin>>kode[a]; cout<<"-------------"<<endl; if(strcmp(kode[a],"HO")==0 ||strcmp(kode[a],"ho")==0) { strcpy(merk,"HONDA"); cout<<"1. Honda Mobilio = Rp.600.000/hari"<<endl; cout<<"2. Honda Jazz = Rp.400.000/hari"<<endl; cout<<"3. Honda Civic = Rp.700.000/hari"<<endl; cout<<"4. Honda Brio = Rp.500.000/hari"<<endl; cout<<"masukan angka mobil :"; cin>>mobil[a]; if(mobil[a]==1) harga[a]=600000; else if(mobil[a]==2) harga[a]=400000; else if(mobil[a]==3) harga[a]=700000; else if(mobil[a]==4) harga[a]=500000; } else if(strcmp(kode[a],"TO")==0 ||strcmp(kode[a],"to"==0) <<<<<here is where the error { strcpy(merk,"TOYOTA"); cout<<"1. Toyota Innova = Rp.500.000/hari"<<endl; cout<<"2. Toyota Avanza = Rp.300.000/hari"<<endl; cout<<"3. Toyota Yaris = Rp.350.000/hari"<<endl; cout<<"4. Toyota Veloz = Rp.450.000/hari"<<endl; #包括 #包括 #包括 #包括 main() { char kode[6][12],merk[15]; int j,a,美孚[6],班雅克[6]; 长哈尔加[6]; 有一个打字错误 else if(strcmp(kode[a],"TO")==0 ||strcmp(kode[a],"to"==0)

“可以转换”;“bool”;变成;常量字符“;错误和错位else错误c++; 我正在学习C++。我遇到了一个无法将“bool”转换为“const char”的错误,这是我能运行的“first strcmp”中最烦人的错误。在那之后,我得到了错误。我试图修复它,但如果我这样做了,就会显示出很多错误。我被困在这里,不知道该怎么办 #include<stdio.h> #include<conio.h> #include<iostream.h> #include<string.h> main() { char kode[6][12],merk[15]; int j,a,mobil[6],banyak[6]; long harga[6]; cout<<"\t\t\t|----------------------------|"<<endl; cout<<"\t\t\t|***Rental mobil sederhana***|"<<endl; cout<<"\t\t\t| ***Jl. Tebet raya no.15*** | "<<endl; cout<<"\t\t\t|----------------------------|"<<endl; cout<<" "<<endl; cout<<"merk mobil yang tersedia : 1. DAIHATSU Kode : DA"<<endl; cout<<" 2. TOYOTA Kode : TO"<<endl; cout<<" 3. HONDA Kode : HO"<<endl; cout<<"Banyak mobil yang ingin disewa : "; cin>>j; banyak[j]=0; if(j<=0) { for(a=1;a<=j; a++) { cout<<"Mobil ke :"<<a<<endl; cout<<"kode merk :"; cin>>kode[a]; cout<<"-------------"<<endl; if(strcmp(kode[a],"HO")==0 ||strcmp(kode[a],"ho")==0) { strcpy(merk,"HONDA"); cout<<"1. Honda Mobilio = Rp.600.000/hari"<<endl; cout<<"2. Honda Jazz = Rp.400.000/hari"<<endl; cout<<"3. Honda Civic = Rp.700.000/hari"<<endl; cout<<"4. Honda Brio = Rp.500.000/hari"<<endl; cout<<"masukan angka mobil :"; cin>>mobil[a]; if(mobil[a]==1) harga[a]=600000; else if(mobil[a]==2) harga[a]=400000; else if(mobil[a]==3) harga[a]=700000; else if(mobil[a]==4) harga[a]=500000; } else if(strcmp(kode[a],"TO")==0 ||strcmp(kode[a],"to"==0) <<<<<here is where the error { strcpy(merk,"TOYOTA"); cout<<"1. Toyota Innova = Rp.500.000/hari"<<endl; cout<<"2. Toyota Avanza = Rp.300.000/hari"<<endl; cout<<"3. Toyota Yaris = Rp.350.000/hari"<<endl; cout<<"4. Toyota Veloz = Rp.450.000/hari"<<endl; #包括 #包括 #包括 #包括 main() { char kode[6][12],merk[15]; int j,a,美孚[6],班雅克[6]; 长哈尔加[6]; 有一个打字错误 else if(strcmp(kode[a],"TO")==0 ||strcmp(kode[a],"to"==0),c++,C++,看来你是说 else if( strcmp( kode[a], "TO" ) == 0 || strcmp( kode[a], "to" ) == 0 ) 注意这些陈述的顺序 cout<<"Banyak mobil yang ingin disewa : "; cin>>j; banyak[j]=0; if(j<=0) 调用未定义的行为。查看错误所在的行。查看括号和比较所在的行。@hivert它的问题现在已经解决了,谢谢!谢谢!我的代码现在可以工作了,因为我忘

看来你是说

else if( strcmp( kode[a], "TO" ) == 0 || strcmp( kode[a], "to" ) == 0 ) 
注意这些陈述的顺序

cout<<"Banyak mobil yang ingin disewa : "; cin>>j;
banyak[j]=0;
if(j<=0)

调用未定义的行为。

查看错误所在的行。查看括号和比较所在的行。@hivert它的问题现在已经解决了,谢谢!谢谢!我的代码现在可以工作了,因为我忘了在上面添加“if”和你说的打字错误。但是我在“banyak[j]上的错误在哪里=0;?@增量,如我在回答中所述,如果j<0,则有人试图访问数组之外的内存。
banyak[j]=0;