So I started learning C++ yesterday and I came across this concept: If, else if and else and Switch. What is the difference in this code?
include <iostream>
using namespace std;
int main() {
int age;
cout<<"Enter your age: "<<endl;
cin>>age;
if (age==15) {
cout<<"You are 15";
}
else if (age==6) {
cout<<"You are 6";
}
else {
cout<<"You are neither 15 nor 6.";
}
return 0;
}
and this:
include <iostream>
using namespace std;
int main() {
int age;
cout<<"Enter your age: "<<endl;
cin>>age;
switch (age)
{
case 15:
cout<<"You are 15";
break;
case 6:
cout<<"You are 6";
break;
default:
cout<<"You are neither 15 nor 6";
break;
}
return 0;
}