Bug in c++ program during a simple loop -
i'm trying solve problem few lines of code possible.
problem statement:
managed hello if several letters can deleted typed word resulted in word "hello"... i'm testing if or not
#include <iostream> int main() { char c; int i=0; while(i!=5 && (cin>>c) && c!='\n'){ if(c=="hello"[i]) i++; } cout<<((i==5)?"yes":"no"); } there's bug when should print "no". program waits more input. think loop doesn't finish until i==5 never finishes when c=='\n'.
before pack program minimize loc (and assume have reason care because otherwise foolish thing do) make right!
try putting != 5 test before cin >>c test. otherwise read 1 character when "hello"
edit: clear, code in question has been modified incorporate suggestion.
Comments
Post a Comment