#11:条件に合わせて処理を変える(1)
ここでは、if を使って、さらに複雑な処理をおこないます。まずは、if のコードに、条件が成立しなかった場合のコードを追加します。さらに、if のコードに、複数の条件を追加します。
#include <iostream>
using namespace std;
int main() {
string name;
cin >> name;
cout << "Hello " << name << endl;
if (name == "c++") {
cout << "Welcome" << endl;
} else {
cout << "Goodbye" << endl;
}
}
#include <iostream>
using namespace std;
int main() {
string name;
cin >> name;
cout << "Hello " << name << endl;
if (name == "c++") {
cout << "Welcome" << endl;
} else if (name == "C++") {
cout << "Good morning" << endl;
} else {
cout << "Goodbye" << endl;
}
}