why can not understand why the loop just goes on and on

Write your question here.

 ``123456789101112131415161718192021222324252627`` ``````#include #include using namespace std; int a,b; char id2; int f1(); int main() { cout<<"PASSWORD= "; while(a!=13) { int f1(); if(a<400) { cout<<"&"; } } } int f1() { a=getch(); if(a==0||a==240){a=500;b=getch();} }``````
It will end when a == 13 (int value 13).

You need to check what value is going into a.

 ``12345678910111213141516171819202122232425262728`` ``````#include #include using namespace std; int a,b; char id2; int f1(); int main() { cout<<"PASSWORD= "; while(a!=13) { int f1(); if(a<400) { cout<<"&"; } } } int f1() { a=getch(); std::cout << "value of a: " << a << std::endl; if(a==0||a==240){a=500;b=getch();} }``````

You've been here ages now. Start thinking about how to solve these problems for yourself. Debugging starts simple. Just output the values and see what they are.

`int getch();`
that's the prototype of `getch()', note how you are calling it
`a=getch();`
you simply write the name of the function, and between parenthesis pass all the needed parameters.

now see what you're doing with `f1()'.
 ``123`` `````` while(a!=13) { int f1();``````
¿why do you have `int' there? that's not a function call, which should be simply `f1();`

So you've got an infinite loop because `a' never changed because `f1()' was never called.

Also, don't litter your code, use a debugger.
you are absolutely right
see what i am doing with int f1()
that's not a function call which should be simply f1();
so i have got an infinite loop because a never has changed because
Last edited on
Registered users can post here. Sign in or register to post.