Example of a Switch Statement Program
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Please enter a
number: ";
cin>>n;
switch (n) {
case 1: {
cout<<"n is equal to 1! ";
break;}
case 2: {
cout<<"n is equal to 2!";
break;}
case 3: {
cout<<"n is equal to 3!";
break;}
default: {
cout<<"n isn't equal to 1,
2, or 3.";
break;}
}
system("PAUSE");
return 0;}
Additional Example
of a Switch Statement Program (For those who are asking)
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
char n;
cout<<"Please
enter a letter from A to C: ";
cin>>n;
switch (n) {
case a: {
cout<<"The
user of this program is a real beauty that he/she will add a comment
to this post. ";
break;}
case b: {
cout<<"The
user of this program is very intelligent that he/she will add a
comment to this post. ";
break;}
case c: {
cout<<"The
user of this program is a great person that he/she will add a comment
to this post.";
break;}
default: {
cout<<"The
user of this program is simply amazing!!!";
break;}
}
system("PAUSE");
return 0;}
a program that explains a lot.. thanks!!
ReplyDeleteREALLY..
Deletethanks for the info here..
ReplyDeleteyou are very much welcome!!
Deletemore examples please!!
ReplyDeletenice blog..
ReplyDeletevery helpful
ReplyDeletecan i put as many cases as i want?
ReplyDeleteYes as long as the cases are different from each other.
ReplyDeletec++ only?
ReplyDeleteit is also applicable to c language.. just change some of the syntax and it will run properly..
Deletethanks for asking by the way..
DeleteAmazing!
ReplyDeletethis program goes to c and c++ language.. you just need to change some syntax but the logic is the same.
ReplyDeleteow yes! got it!!
ReplyDeleteI need more SAMPLES!!! :D
ReplyDeletemy friend.. here is another example.. hope this helps you. ^_^
DeleteThis blog is very halpful. Thanks
ReplyDeleteIt's brilliant to have a blog like this. :)
ReplyDeleteThanks for this^_^
ReplyDeletenice!!!
ReplyDeletethank you :)
ReplyDeletethe syntax is easy and convenient to use for c and c++..
ReplyDeletenICE :)
ReplyDeletemakaktulong to :D
ReplyDeletemore samples please!!!
ReplyDeletehere is another example of a switch a program.. sorry for the late update! i hope this helps you a lot !
Deletea simple program for simple thinkers like me...
ReplyDeletemooooore !! I love this blog :D
ReplyDeleteThis is hart hart!
ReplyDeleteit works when i tried it on the programming application.. thanks for this!
ReplyDeleteyes it works when i tried it too..
Deletenice example..
ReplyDeletenice.. great!.. i really love your blog!
ReplyDeletethanks!!
Deletedoes this work with other programming languages??
ReplyDeletethe logic yes.. you just have to change the syntax but the output woud be the same..
ReplyDeletei see.. thanks for this ms author!!
Deleteyou're very much welcome.. visit my blog anytime ok??? ^_^
Deletethe second example is funny.. but it suits me heheh! thanks!!
ReplyDelete