• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

1 line error code (average formula), please check. URGENT

can someone check my code and see how can i fix the error on the formula?

The error comes in this line:
promedio=(d[cont].nota1)+(d[cont].nota2)+(d[cont].nota3)/3);

I have to calculate the average for 3 califications.

p.s. I am using DevC++
#include <stdio.h>

struct student
	{
		char nombre[50];    // name of the student
		int anio[4];         // year
		float nota1[3];	    // first calification
		float nota2[3];	    // second calification
		float nota3[3];	    // third calification
		float promedio[8];  // THIS IS THE AVERAGE
		char estado[1];     // APPROVED OR REJECTED?
	};

int main(void)
    {
	          struct student d[30];
	          int cont;
              float average;

	           for(cont = 0; cont < 30; cont++)
                        {
		                 printf("Name: ", &cont);
                         scanf("%s", d[cont].nombre);
                         printf("Ingrese Año Lectivo: ");
		                 scanf("%s", &d[cont].anio);
		                 printf("Ingrese Primera Nota del Certamen: ");		       
		                 scanf("%d", &d[cont].nota1);
		                 printf("Ingrese Segunda Nota del Certamen: ");		       
		                 scanf("%d", &d[cont].nota2);
		                 printf("Ingrese Tercera Nota del Certamen: ");		       
		                 scanf("%d", &d[cont].nota3);             
                         
                         average=(d[cont].nota1)+(d[cont].nota2)+(d[cont].nota3)/3);
                         printf("The average is;,%.2f",average);

Open in new window

0
José Perez
Asked:
José Perez
  • 7
  • 4
  • 2
1 Solution
 
ozoCommented:
parentheses are unbalanced.
there are three  left ( and four right )
0
 
José PerezAuthor Commented:
for some reason it did not paste the first one, any way, it does no change, the error is the following:

invalid operands of types `float[3]' and `float[3]' to binary `operator+'
0
 
ozoCommented:
d[cont].nota1 and d[cont].nota2 are arrays of three floats
+ does not work on arrays.
Did you want to select a particular element of the array?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
José PerezAuthor Commented:
The current element of the array, defined by "cont"

what would you suggest?
0
 
ozoCommented:
d[cont] selects an element of the d array.
to get a float, you need to select an element of the nota1 array

I don't think you want to use cont to select from the nota1 array, since the nota1 array has only 3 elements,
and the value of cont can be greater than 2

But it's not clear why you'd want to declare nota1 as an array of floats, instead of as a float anyway.
0
 
José PerezAuthor Commented:
Honestly I dont know how to do it, I just tried to do this way but it does not work. If you see i just want to calculate the average of nota1+nota2+nota3.

can you propose some way to fix this program?
0
 
José PerezAuthor Commented:
I fix it!!!!!

the solution is doing this:

            float nota1;
            float nota2;
            float nota3;
0
 
José PerezAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for oscargarin's comment http:/Q_27409811.html#37009925

for the following reason:

I found the answer by my self.
0
 
ozoCommented:
declaring nota1 a float instead of an array was one of the suggestions
0
 
Hugh McCurdyCommented:
Note to moderator: I agree with Ozo.  While the author did solve the problem, he/she did so after Ozo posted sound assistance that was used in the solution.
0
 
José PerezAuthor Commented:
ok. what is suggested in case an answer was part of the solution?
0
 
José PerezAuthor Commented:
will it be fair to award 100 point each?
0
 
Hugh McCurdyCommented:
It's not uncommon for an author to be involved in solving the problem.  IMH(unofficial)O the helper(s), in this case Ozo, should still credited for their effort.

If I asked the question, I would have awarded all the points.  (You can't actually award points to yourself anyway.)  But you should do what you feel is fair.

Whatever you do, don't give me any points.  I didn't help solve the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now