-
Notifications
You must be signed in to change notification settings - Fork 2
/
31.cpp
39 lines (37 loc) · 897 Bytes
/
31.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<ctype.h>
#include<string>
int main()
{
//program to toggle case
std::string str;
bool flag=true;
std::cout<<"Enter the string : ";
getline(std::cin,str);
//always remember isalpha() and isupper() function return positive integer value when the condition is true
for(int i=0;i<str.length();i++)
{
if(isalpha(str[i])>0)
{
if(isupper(str[i])>0)
{
str[i] = tolower(str[i]);
}
else
{
str[i] = toupper(str[i]);
}
}
else
{
std::cout<<"String is not alphabetical"<<std::endl;
flag=false;
break;
}
}
if(flag==true)
{
std::cout<<"Toggle case of the string : "<<str<<std::endl;
}
return 0;
}