1
My code is a question, I’m learning to program and using the site codcad, the question is in the image. When I send my code, it only gives 60 points of 100. I wonder what I’m doing wrong.
Follow the image.
Edit:I tried to solve the issue using only what I learned on the site, more advanced things still do not know very well, so I may have gone for a more complicated logic.
Question Obs:The question is related to a list of exercises on if. Carnival (OBI 2012, Phase 2, Level 1)
Carnival is a holiday usually celebrated in February; in many Brazilian cities, the main attraction are the school parades of samba. The various associations parade to the sound of their sambas-plots and are judged by the league of samba schools to determine the champion of Carnival.
Each association is evaluated in several categories; in each category, each school receives five grades ranging from 5.0 to 10.0. The final grade of the school in a given category is the sum of the three central notes received by the school, excluding the highest and lowest of the five grades.
As there are many samba schools and many inquiries, the president The League asked you to write a program that, given the notes of the association, calculates its final grade in a given category.
Input The entry contains a single line, containing five Ni(1 i 5), all to one decimal place, indicating the notes received by association in one of the items.
Output Your program must print a single line, containing a single line number with exactly one decimal place, the final grade of the school of samba in the category considered.
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;
}
}
}
BS: I’m sorry for anything I’ve done wrong I’m new to the site and if I’m done something wrong I accept suggestions and tips. Obs2: I accept tips and suggestions tbm for programming issue. Grateful for the attention.
Hello Prometheus. Logic doesn’t have to be this complicated. Read the 5 notes for a
vector
, sort them (e.g., usingstd::sort
) and add the three middle elements.– Anthony Accioly
Also check that your output always has a decimal place:
std::cout << std::fixed << std::setprecision(1) << somaNotas;
– Anthony Accioly
I’m sorry I lacked information in my question, this tip of yours by what I researched should solve, but I am very new in programming and if it is possible to give me a simpler explanation would be grateful, because I used everything I know so far.
– Prometheus
A good start would be to post the statement in text, not a screen print.
– Bacco
okay, I thought it would look really bad the whole text here, I’ll add the statement.
– Prometheus