Hello all, i'm new to this forum.
I need help with this code. Its actually a sample from a large program. Here the computer would ask for an integer input. When I give say 1 or 2 or 3 , the program continues and assigns new values to n, as long as the loop goes. but if I give '.' or '/' , the value of n remains the previous value and the compiler does not ask for the value of n anymore. What should I do to handle this exception?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream>
usingnamespace std;
void main()
{
int n;
do
{
cout<<"Enter a value of n:";
cin>>n;
cout<<"\n The value of n: "<<n<<endl;
system("pause");
}while(n!=0);
}
Enter a value of n:6
The value of n: 6
Press any key to continue . . .
Enter a value of n:9
The value of n: 9
Press any key to continue . . .
Enter a value of n:4
The value of n: 4
Press any key to continue . . .
Enter a value of n:.
The value of n: 4
Press any key to continue . . .
Enter a value of n: The value of n: 4
Press any key to continue . . .
Enter a value of n: The value of n: 4
Press any key to continue . . .
Enter a value of n: The value of n: 4
Press any key to continue . . .
#include<iostream>
usingnamespace std;
void main()
{
char n(0);
do
{
cout<<"Enter a value of n:";
cin>>n;
if(!isdiget(n))
continue;
cout<<"\n The value of n: "<< n<<endl;
system("pause");
}while(n!='0');
}