Using Range in the Case Values of Switch Statement | C++ Programming Video Tutorial

preview_player
Показать описание
In this c++ programming video tutorial you will learn to use Range in the switch statement case values with example.

GCC Compiler allows you to use this feature. usage of the range in the case values of the switch statement allows the programmer to execute a set of statements for a range of values.

Syntax for using the Range in switch case values
case LowerLimit ... upperlimit:

while using this feature you have to follow 2 rules.
LowerLimit can not be greater than the upperlimit.
none of the cases should contain overlapping values ( one value should not have matches in 2 or more cases ).

Subscribe for more tutorials

Social Media Links

#CPP #C++Programming #LearningLad #ComputerProgramming
Рекомендации по теме
Комментарии
Автор

Thanks for your tutorials.

#include <iostream>
using namespace std;
int main()
{
char input ;
cout<<"Enter the alphabet:";
cin>> input;
switch(input){
case 'A' ... 'Z' :cout<<"You Entered upper case";
break;
case 'a' ... 'z':cout<<"You Entered lower case";
break;
}
return 0;
}

shamsirdoha
Автор

those dots helped me so dam much thank u, I had to find a way to only use switch statements to validate that the cinput wouldnt go below 0 in the negatives. THANK YOU

MinecraftMen
Автор

WOW! i almost learned C++ program thank you i watched all your series

divergent
Автор

#include <iostream>
using namespace std;
int main(){
char result = 'G';
int ascii = int(result);
switch(result){
case 97 ... 122:{
cout <<result <<" is lowercase.";
break;
}
case 65 ... 90:{
cout <<result << " is uppercase.";
break;
default:{
cout << "you have no matching character";
}
}
}
return 0;
}

rohitpingale
Автор

#include <iostream>

using namespace std;

int main()
{char x;
cout << "Please insert a char" << endl;
cin >> x;

switch(x){

case 'A' ... 'Z':
cout << "alphabet is in higher case";
break;
case 'a' ... 'z':
cout << "alphabet is in lower case";
break;
default:
cout << "no alphabet found";
}


return 0;

}

ong
Автор

Thanks man for your wonderful videos, I have watched lots of them, I hope on day I can finish them.

masouddayaghi
Автор

#include<iostream>
using namespace std;
void main()
{
char x;
cin>>x;
switch(x)
{ case 65 ... 90 :
cout<<"upper case";
case 97 ... 122 :
cout<<"lower case";
}
}

tarunsingh
Автор

Thank you very much! Your video helped me to finish my project.

andrericalde
Автор

Thanks sir i solved my home work easily

waseemsajjad
Автор

Thank you so much it was a really really nice explanation!

aryanshmahato
Автор

Love from Pakistan. Thank you so much Anil. You videos are very helpful.

umarbinazeem
Автор

#include<iostream>

using namespace std;



int main(){
char x;
cin >> x;

switch(x){
case 'a' ... 'z':

cout << " is a lowercase letter ";

break;

case 'A' ... 'Z':
cout << "is a uppercase letter";
break;

default:
cout << "default statements";
break;

}
return 0;
}

trader_akhilesh
Автор

Identifing uppercase and lowercase:
#include <iostream>
using namespace std;
int main(){
char letra;
cout<<"Ingrese La Letra A Identificar :"<<endl;
cin>>letra;
switch (letra){
case 65 ... 90:
cout<<"Es Mayuscaula"<<endl;
break;
case 97 ... 122:
cout<<"Es Minuscula"<<endl;
break;
default:
cout<<"NO ES UNA LETRA"<<endl;
}
}

edgardo
Автор

#include <iostream>
Using namespace std;
Int main ( )
{
Char input;
Cout <<"Enter the Alphabet"<<endl;
Cin>> input;
Switch (input) {
Case 'A' ... 'Z':{
Cout <<" You entered Uppercase Character";
Break;
}
Case 'a' ... 'z': {
Cout <<" You entered Lowercase Character";
Break;
}
Default :{
Cout <<" You Entered wrong Character";
}
}
Return 0;
}

justin.p.oommen
Автор

made the user enter some value:src code is here:

#include <iostream>

using namespace std;

int main()
{
int x ;
cout<<"enter some value"<<endl;
cin>>x;

switch(x)
{
case 1 ...10:
cout<<"this is range 1:"<<endl;
break;
case 11 ... 20:
cout<<"this is range 2:";
break;
case 21 ... 30:
cout<<"this is range 3:";
break;
default:
cout<<"enter some values";



}
}

HallOfMemeYT
Автор

Hello I am wondering if there is a way to use range but exclusive (not including the start and end numbers). Thank you your videos are awesome keep it up

tropicomango
Автор

#include <iostream>
using namespace std;
int main()
{char input;
cout<<"Enter a letter"<<endl;
cin>>input;
switch (input)
{case 'A' ... 'Z' :
 cout<<"You have entered an uppercase letter";
 break;
 case 'ba' ... 'z':
  cout<<"You have entered a lowercase letter";
  break;
  default :
   cout<<"You have not entered a letter";
}
}

Finalleigh
Автор

Here's my way of doing your challenge program.

#include <iostream>

int main()
{
char ch{};
std::cin >> ch;

switch ((int)ch)
{
case 65 ... 90:
std::cout << "Entered character is in UPPERCASE.\n";
break;
case 97 ... 122:
std::cout << "Entered character is in lowercase.\n";
break;
default:
std::cout << "Please enter from a-z (lowercase) or A-Z (uppercase)\n";
}

return 0;
}

jainamparikh
Автор

Beautiful! Thank you. For your valuable information

azadlevent
Автор

thank you so much, it was very useful

jenniferpaolazarateramirez