Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a function which takes as parameters the beginning of the list, a hint(A,B,C,D) and the number of the question. Its task is to decide if I guessed the correct answer correctly. However, combined with the back working of the program, I think something may have gone wrong
bool helyesValasz(Adatok *eleje, char tipp, int kerdes) {
    Adatok *jelenlegi = eleje;

    for (int i = 1; i < kerdes && jelenlegi != NULL; i++) {
        jelenlegi = jelenlegi->kovetkezo;
    }

    if (jelenlegi == NULL) {
        return false; 
    }
    return (toupper(tipp) == toupper(jelenlegi->valasz));
}


What I have tried:

I have tested a lot, tried to debug but couldnt.
Posted
Updated 25-Nov-23 21:45pm
v2
Comments
Mike Hankey 25-Nov-23 16:18pm    
The code looks like it ought to work, what is it doing that is wrong?

I guess it should be
C++
bool helyesValasz(Adatok *eleje, char tipp, int kerdes) 
{
    Adatok *jelenlegi = eleje;

    for (int i = 1; i < kerdes && jelenlegi != NULL; i++) 
    {
        if ( (toupper(tipp) == toupper(jelenlegi->valasz) )
        {
            return true; // foud
        }

        jelenlegi = jelenlegi->kovetkezo;
    }
    return false; 
}
 
Share this answer
 
If it is a C program, you would need a special header for the declaration of bool. Alternatively, you could use the data type directly in C++. The program seems to meet the requirement exactly. Even if we take into account the parts already known from the other questions, the function is correct.

With the implementation of kerdes, I am a little unsure whether the comparison with the index i would be reliable enough. Perhaps it would be better if a number from the Adatok structure were compared instead of the loop index i. Either would work, depending on what you want.
 
Share this answer
 
v2
It would be better to use english names because me (as a german) dont understand your "kovetkezo". Now you are stepping with that linked element. Maybe it is used as "before" pointer.
As merano99 wrote without the "Adatok" and it usage it is only guessing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900