+ 2
Write a program which takes input as integer only that is restrict other characters form inputs ?
c++ program which is important for a good programmer.
11 odpowiedzi
+ 14
int main()
{
int x;
while (!(cin >> x))
{
cin >> x;
cin.clear(); cin.ignore(512, '\n');
}
cout << "You entered : " << x;
return 0;
}
+ 13
What do you mean by removing one digit?
+ 5
Please refer
https://code.sololearn.com/cvbzeX3s8MN7/#cpp
Try it on your PC as it may not work on Playground
+ 4
#include<iostream.h>
#include<conio.h>
int getintegerOnly();
int main()
{
int x=0;
clrscr();
x=getintegerOnly();
cout<<"/n you have "<<x;
getch();
return 0;
}
int getintegerOnly()
{
int num=0;char ch;
do
{
ch=getch();
if(ch>=48&&ch<=57)
{
cout<<ch;
num=num*10+(ch-48);
}
if(ch=='\b')
{
clrscr();
num=num/10;
cout<<num;
}
if(ch==13)
{
return(num);
}}while(1);}
+ 3
suppose first input 1 and second input 2 and third input 3 then we can see 123 on console screen but we want to remove 3 (last digit of number) on Console screen then output 12 . if want to remove again last digit then output 1.
+ 2
if we want to removing one digit on Console screen when what do you do?
+ 2
Great! But I have a doubt whether clrscr () function is supported by current C++ version
+ 2
Then hats off to you I tried the same way back in 1995, hard to recall.
+ 2
Make a little change - use getche () instead of getch (). You will see the difference.
+ 1
no sir but my answers according to turbo c++
0
yes sir but we want to taking only integers value according to question .when we use getche() we can takes character and integers so we can use getch().