ここに私のコードです。 if文に入力した式は機能しません。私は "a"と入力したときにパンを言い、 "b"と入力するとワインを言うように、私はどのような変更を行うべきですか?
#include <iostream>
using namespace std;
int main(){
int value;
cout << "a) Bread" << endl;
cout << "b) Wine" << endl;
cout << endl;
cout << "Please enter the letter of the type of product you want to buy: " << endl;
cin >> value;
if(value == a){
cout << "You chose bread";
} else{
cout << "You chose wine";
}
return 0;
}
「a」という名前の変数がないため、コードがコンパイルされません。 'int'を' const char'の代わりに未定義の変数と比較しようとしています。 –
- "if"行の左側に赤い四角形が現れます と私は思っています(値== a)は無効です –
これはちょうどタイプミスですが、aとbの両側に引用符が必要です –