Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make my test result succesfull?

–2 votes
asked Feb 7 by Adomas Jurevičius (120 points)
Hi, I did a programming task in the classroom, when I click test I get fail 0 out of 3. I know because of the cout thing, but how can I fix that and make that it would be 3 out of 3 when I click test?

This is my code:

#include <iostream>
using namespace std;

int main()
    int n;
    bool negative=false;
    bool lower=false;
         cout<<"Įvesk kiek viso turi pažymių: ";
    float paz[n];
    for(int i=0;i<n;i++)
          cout<<"Įveskite pažymį \n"<<i+1<<": ";

        if(paz[i]>=0 && paz[i]<7)


    else if(lower==true)

    return 0;

2 Answers

0 votes
answered Feb 12 by xDELLx (7,630 points)
Try to debug the code , write sample tests urself & see how code works for these tests on  blank sheet.

Also I would suggest using switch case for the multiple if else sequenece you have used, it would cleaner.

Also It would great the problem statement was shared as here IN ENGLISH  we cant see the prob statement & have acces to your internal sites.

Apart from above observations ,lets consider you have an array element as 3, so the lower & negative  variables would be set to true.IS this expected & should they be reset later in the loop , if any of these is set ,should the other be reset ?

This would be clear only if the exact problem is shared .
0 votes
answered Feb 15 by Peter Minarik (22,320 points)
edited Feb 15 by Peter Minarik


I'm not sure what this program is doing.

Let me write some pseudo code of what it does:

grades = readGrades();
if (grades.Any(grade < 4)) consultationIsMandatory = true;
if (grades.Any(0 <= grade && grade < 7)) consultationIsAdvised = true;
if (grades.All(7 <= grade)) consultationIsOptional = true;

So to me it means that if all the grades are at least 7, then all is good.

However, it's strange that for grades less than 4 consultations are mandatory and advised at the same time. Did you want to make advised for range [4, 7[ perhaps?

Also, without having the test cases, it's hard to tell why exactly they fail. At least the requirements would be nice to have so we know what the program is supposed to do.


I haven't noticed xDELLx's post when I posted mine. It seems like we had the same idea. :)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.