I would like to know what is wrong with my code?

1

My code is a question, I'm learning to program and using the codcad site, the question is in the image. When I send my code, it only has 60 points of 100. I would like to know what I am doing wrong.

Follow the image.

Edit: I tried to solve the question using only what I learned on the site, more advanced things still do not know very well, so I may have gone through a more complicated logic.

  

Questionobs:Thequestionisrelatedtoalistofexercisesaboutif.Carnival(OBI2012,Phase2,Level1)

    

CarnivalisaholidaynormallycelebratedinFebruary;inmany  Braziliancities,themainattractionistheparadesofschoolsof  samba.Thevariousassociationsgotothesoundoftheirsambas-tangosand  arejudgedbytheleagueofsambaschoolstodeterminethechampion  ofCarnival.

    

Eachassociationisevaluatedinseveralaspects;ineachcase,each  schoolreceivesfivegradesvaryingfrom5.0to10.0.Thefinalgradeof  schoolinagivenitemisthesumofthethreecentralnotesreceived  bytheschool,excludingthehighestandlowestofthefivegrades.

    

Astherearemanysambaschoolsandmanyquests,thepresident  askedyoutowriteaprogramthat,giventhe  

     

Input The input contains a single line, containing five Ni numbers (1≤   i ≤5), all with one decimal place, indicating the notes received by the   association in one of the requirements.

     

Output Your program should print a single line, containing a single   number with exactly one decimal place, the final grade of the school of   samba in the considered subject.

     

Restrictions
  5.0 ≤Ni ≤10.0

**Exemplos de Entrada**    ......     *Exemplos de Saída*  
**6.4 8.2 8.2 7.4 9.1**        ......     *23.8*  
**10.0 10.0 5.0 5.0 10.0**     ......     *25.0*

Code

#include <iostream>

using namespace std;

int main(){

 double a, b, c, d, e;

 cin>>a>>b>>c>>d>>e;

 if (a>=b and a>=c and a>=d and a>=e){
    if(b<a and b<=c and b<=d and b<=e){
        cout<<c+d+e;
     }
     if(c<b and c<=d and c<=e) {
        cout<<b+d+e;
     }
     if(d<=b and d<c and d<=e){
        cout<<b+c+e;
     }
    if(e<a and e<b and e<c and e<d){
        cout<<b+c+d;
     }
 }
 if (b>a and b>=c and b>=d and b>=e){
    if(a<b and a<=c and a<=d and a<=e){
        cout<<c+d+e;
    }
    if(c<a and c<=d and c<=e){
        cout<<a+d+e;
    }
    if (d<a and d<c and d<=e){
        cout<<a+c+e;
    }
    if(e<a and e<b and e<c and e<d){
        cout<<a+c+d;
    }
 }
 if (c>a and c>b and c>=d and c>=e){
    if(a<=b and a<=d and a<=e){
        cout<<b+d+e;
    }
    if(b<a and b<=d and b<=e){
        cout<<a+d+e;
    }
    if(d<a and d<b and d<=e){
        cout<<a+b+e;
    }
    if(e<a and e<b and e<c and e<d){
        cout<<a+b+d;
    }
 }
 if(d>a and d>b and d>c and d>=e){
    if(a<=b and a<=c and a<=e){
        cout<<b+c+e;
    }
    if(b<a and b<=c and b<=e){
        cout<<a+c+e;
    }
    if(c<a and c<b and c<=e){
        cout<<a+b+e;
    }
    if(e<a and e<b and e<c and e<d){
        cout<<a+b+c;
    }
 }
 if(e>a and e>b and e>c and e>d){
    if(a<=b and a<=c and a<=d){
    cout<<b+c+d;
    }
    if(b<a and b<=c and b<=d){
    cout<<a+c+d;
    }
    if(c<a and c<b and c<=d){
    cout<<b+a+d;
    }
    if(e<a and e<b and e<c and e<d){
        cout<<a+b+c;
    }

 }
}

obs: I'm sorry for anything I've done wrong I'm new to the site and if I'm done wrong I'll accept suggestions and tips. obs2: I accept tips and suggestions as well for programming. Thank you for your attention.

    
asked by anonymous 30.03.2018 / 11:46

1 answer

3

Following is an implementation of the exercise:

#include <algorithm>  
#include <array>   
#include <iomanip>
#include <iostream>
#include <numeric>
#include <tuple>

int main()
{
    std::array<double, 5> notas;
    std::generate(notas.begin(), notas.end(), [] {
        double nota;
        std::cin >> nota;
        return nota;
    });

    decltype(notas)::iterator menor_nota, maior_nota;
    std::tie(menor_nota, maior_nota) = std::minmax_element(notas.begin(), notas.end());

    std::iter_swap(menor_nota, notas.end() - 2);
    std::iter_swap(maior_nota, notas.end() - 1);

    double soma_notas = std::accumulate(notas.begin(), notas.end() - 2, 0.0);

    std::cout << std::fixed << std::setprecision(1) << soma_notas;

    return 0;
}

Here I am using the C ++ Standard Library to do absolutely everything, but you can - and, from a learning point of view, you should - reimplement these algorithms manually using simple loops and logic.

Algorithm logic:

  • Read all the elements for a container ( array , vector , etc)
  • Find the highest and lowest marks
  • Remove (or in this case, move to the end of the container ) found elements
  • Add the remaining elements
  • Print the formatted result correctly
  • 30.03.2018 / 17:31