+ 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.

26th Mar 2017, 7:57 AM
Harish kumawat
Harish kumawat - avatar
11 odpowiedzi
+ 14
int main() { int x; while (!(cin >> x)) { cin >> x; cin.clear(); cin.ignore(512, '\n'); } cout << "You entered : " << x; return 0; }
26th Mar 2017, 8:40 AM
Hatsy Rei
Hatsy Rei - avatar
+ 13
What do you mean by removing one digit?
26th Mar 2017, 8:41 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Please refer https://code.sololearn.com/cvbzeX3s8MN7/#cpp Try it on your PC as it may not work on Playground
26th Mar 2017, 8:31 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 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);}
27th Mar 2017, 4:07 PM
Harish kumawat
Harish kumawat - avatar
+ 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.
26th Mar 2017, 9:11 AM
Harish kumawat
Harish kumawat - avatar
+ 2
if we want to removing one digit on Console screen when what do you do?
26th Mar 2017, 8:35 AM
Harish kumawat
Harish kumawat - avatar
+ 2
Great! But I have a doubt whether clrscr () function is supported by current C++ version
27th Mar 2017, 4:13 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 2
Then hats off to you I tried the same way back in 1995, hard to recall.
27th Mar 2017, 4:16 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 2
Make a little change - use getche () instead of getch (). You will see the difference.
27th Mar 2017, 4:25 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
no sir but my answers according to turbo c++
27th Mar 2017, 4:14 PM
Harish kumawat
Harish kumawat - avatar
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().
27th Mar 2017, 4:51 PM
Harish kumawat
Harish kumawat - avatar