/*Program to read a character and display its next character in the ASCII list*/
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
usingnamespace std;
int main()
{
char ch,Next,ch1;
do
{
cout<<"\nEnter any character : ";
ch=getchar();
Next=ch+1;
cout<<"\nThe next character is : ";
putchar(Next);
cout<<"\nWant to enter more(y/n)";
ch1=getchar();
}
while(ch1=='y'||ch1=='Y');
cout<<"\n";
system("pause");
return 0;
/*Program to read a character and display its next character in the ASCII list*/
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
usingnamespace std;
int main()
{
char ch,Next,ch1;
do
{
cout<<"\nEnter any character : ";
cin>>ch;
Next=ch+1;
cout<<"\nThe next character is : ";
putchar(Next);
cout<<"\nWant to enter more(y/n)";
cin>>ch1;
}
while(ch1=='y'||ch1=='Y');
cout<<"\n";
system("pause");
return 0;
}
/*Program to read a character and display its next character in the ASCII list*/
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
usingnamespace std;
int main()
{
char ch,Next,ch1;
do
{
cout<<"\nEnter any character : ";
ch=getchar();
std::cin.ignore();
Next=ch+1;
cout<<"\nThe next character is : ";
putchar(Next);
cout<<"\nWant to enter more(y/n)";
ch1=getchar();
std::cin.ignore();
}
while(ch1=='y'||ch1=='Y');
cout<<"\n";
system("pause");
return 0;
}
By default, cin ignores all whitespace. getchar() does not, so the prompt asking for 'y' or 'n' is actually reading a newline '\n', which fails the loop condition.