first of answering , helping out...
making program let user enter number... , use program point out total number of 4's in the number entered , have encountered problem..
this first post here please excuse me if make mistakes..
the code
int main() { int t,i,j,l; char n,p[10]; cin>>t; while(t--) //the number of times user can enter new number { cout<<"\nenter numbers\n"; l=0;i=0; { n=getch(); //getch used enter key need not pressed , //number looks whole , each number //individually stored p[i]=n; //here number entered stored in p cout<<n; //to display number l++;i++; }while(n!=' '); //now here between '' has present loop //terminates enter key pressed right //as spacebar hit loop terminate. cout<<"\n"; j=0; for(i=0;i<l;i++) //using l loop runs accordingly { if(p[i]=='4') { j++; //for couting number of 4's } cout<<p[i]<<"\n"; //wont needing in final program here cout // check output } cout<<"\n there "<<j<<" fours\n"; } }
please not have solution program please not provide different code using different logic... need same program work.i know program can made work using string length here want loop terminate after enter key pressed.
you can see check if n equal '\r'. while loop looks like
{ n=getch(); //getch used enter key need not pressed , //number looks whole , each number //individually stored p[i]=n; //here number entered stored in p cout<<n; //to display number l++;i++; }while(n!='\r');
Comments
Post a Comment